ydb-platform / ydb

YDB is an open source Distributed SQL Database that combines high availability and scalability with strong consistency and ACID transactions
https://ydb.tech
Apache License 2.0
4k stars 565 forks source link

Set current CompatibilityInfo outside of driver_lib #2478

Closed serbel324 closed 8 months ago

serbel324 commented 8 months ago

How it works now:

Information about compatibility is stored in the form of protobuf in a global object CompatibilityInfo of type TCompatibilityInfo: https://github.com/ydb-platform/ydb/blob/main/ydb/core/driver_lib/version/version.h#L169 To change the compatibility information for binary we need to change the constructor: https://github.com/ydb-platform/ydb/blob/stable-23-3/ydb/core/driver_lib/version/version.cpp#L27

The problem with this approach is that NBS uses YDB code by directly linking it without copying or modifying, therefore, in their binary the compatibility information remains the same as in arcadia/ydb.

What is proposed:

We propose to move the construction of the current compatibility information into a separate function and define this function in a separate source file, differing for NBS and YDB. This can be main.cpp or some new file.

How it would look with the main.cpp option:

ydb/core/driver_lib/version/version.cpp

...

TCompatibilityInfo::TCompatibilityInfo() {
    ...

    auto current = MakeCurrentCompatiblityInfo();

    ...
}

...

ydb/apps/ydbd/main.cpp

...

#include <ydb/core/driver_lib/version.h>

...

NKikimrConfig::TCurrentCompatibilityInfo TCompatibilityInfo::MakeCurrentCompatiblityInfo() {
    using TCurrentConstructor = TCompatibilityInfo::TProtoConstructor::TCurrentCompatibilityInfo;
    using TVersionConstructor = TCompatibilityInfo::TProtoConstructor::TVersion;

    return TCurrentConstructor{
        .Application = "ydb",
        .Version = TVersionConstructor{
            .Year = 23,
            .Major = 3,
        }
    }.ToPB();
}

...

cloud/blockstore/apps/server/main.cpp and cloud/filestore/apps/server/main.cpp


...

#include <ydb/core/driver_lib/version.h>

...

NKikimrConfig::TCurrentCompatibilityInfo TCompatibilityInfo::MakeCurrentCompatiblityInfo() {
    using TCurrentConstructor = TCompatibilityInfo::TProtoConstructor::TCurrentCompatibilityInfo;
    using TVersionConstructor = TCompatibilityInfo::TProtoConstructor::TVersion;

    return TCurrentConstructor{
        .Application = "nbs",
        .Version = TVersionConstructor{
            .Year = 23,
            .Major = 3,
        }
    }.ToPB();
}

...
serbel324 commented 8 months ago

I think it would be better to define the version for YDB app in a separate file, rather than main.cpp, to link this file in UT configurations.

serbel324 commented 7 months ago

https://github.com/ydb-platform/ydb/pull/2753