Skip to content

Commit

Permalink
SPDB-347: Add a version number to our builds
Browse files Browse the repository at this point in the history
The change set includes:
1) A header file that contains the Major, Minor, and Patch versions of speedb
as a macro, as well as a set of functions returning info about how/when/where
this version of speedb was created.

also includes all changes done on build_version.cc.in in the following commits:
1. version: remove superfluous build property
The `speedb_build_spdb_key` property is unused and was accidentally
imported as part of #1.

2.general: replace RocksDB references in strings with Speedb (#64)
This includes references in statuses as well as tools output.

3.build: add a version build-tag for non-release builds (#156)
The build tag can be set during the build (using either the Makefile
or the CMake). If it's not provided, and we're not in a release build,
it will be calculated using the state of the git tree since the last
release tag (for example, for this PR the build tag will be calculated as
`(main+17)-(156-build-add-a-build-tag-into-the-version-for-non-release-builds+1)`.
If the git tree state can not be determined, a question mark will be
used instead.
build_version: apply the build tag to the Speedb version string (#231)

4. The changes in #157 were accidentally applied to the `GetRocksVersionAsString()`
function instead of the `GetSpeedbVersionAsString()` function. This replaced
the RocksDB patch number with the Speedb one, and added the build tag in
the wrong place.
Fix it by moving the logic to the intended function.
  • Loading branch information
Yuval-Ariel committed Nov 23, 2022
1 parent bfe8152 commit ef570e9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 11 deletions.
4 changes: 3 additions & 1 deletion db/db_impl/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
#include "rocksdb/table.h"
#include "rocksdb/version.h"
#include "rocksdb/write_buffer_manager.h"
#include "speedb/version.h"
#include "table/block_based/block.h"
#include "table/block_based/block_based_table_factory.h"
#include "table/get_context.h"
Expand Down Expand Up @@ -4899,7 +4900,8 @@ void DBImpl::EraseThreadStatusDbInfo() const {}
//
// A global method that can dump out the build version
void DumpRocksDBBuildVersion(Logger* log) {
ROCKS_LOG_HEADER(log, "SpeeDB version: %s\n",
ROCKS_LOG_HEADER(log, "SpeeDB version: %s (%s)\n",
GetSpeedbVersionAsString().c_str(),
GetRocksVersionAsString().c_str());
const auto& props = GetRocksBuildProperties();
const auto& sha = props.find("speedb_build_git_sha");
Expand Down
12 changes: 12 additions & 0 deletions speedb/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#define SPEEDB_MAJOR 1
#define SPEEDB_MINOR 5
#define SPEEDB_PATCH 0

namespace ROCKSDB_NAMESPACE {
// Returns the current version of SpeeDB as a string (e.g. "1.5.0").
// If with_patch is true, the patch is included (1.5.x).
// Otherwise, only major and minor version is included (1.5)
std::string GetSpeedbVersionAsString(bool with_patch = true);
} // namespace ROCKSDB_NAMESPACE
47 changes: 37 additions & 10 deletions util/build_version.cc.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,28 @@
#include <memory>

#include "rocksdb/version.h"
#include "speedb/version.h"
#include "rocksdb/utilities/object_registry.h"
#include "util/string_util.h"

// The build script may replace these values with real values based
// on whether or not GIT is available and the platform settings
static const std::string rocksdb_build_git_sha = "speedb_build_git_sha:@GIT_SHA@";
static const std::string rocksdb_build_git_tag = "speedb_build_git_tag:@GIT_TAG@";
static const std::string speedb_build_git_sha = "speedb_build_git_sha:@GIT_SHA@";
static const std::string speedb_build_git_tag = "speedb_build_git_tag:@GIT_TAG@";
#define HAS_GIT_CHANGES @GIT_MOD@
#if HAS_GIT_CHANGES == 0
// If HAS_GIT_CHANGES is 0, the GIT date is used.
// Use the time the branch/tag was last modified
static const std::string rocksdb_build_date = "speedb_build_date:@GIT_DATE@";
static const std::string speedb_build_date = "speedb_build_date:@GIT_DATE@";
#else
// If HAS_GIT_CHANGES is > 0, the branch/tag has modifications.
// Use the time the build was created.
static const std::string rocksdb_build_date = "speedb_build_date:@BUILD_DATE@";
static const std::string speedb_build_date = "speedb_build_date:@BUILD_DATE@";
#endif

#define SPDB_BUILD_TAG "@SPDB_BUILD_TAG@"
static const std::string speedb_build_tag = "speedb_build_tag:" SPDB_BUILD_TAG;

#ifndef ROCKSDB_LITE
extern "C" {
@ROCKSDB_PLUGIN_EXTERNS@
Expand All @@ -46,9 +50,14 @@ static void AddProperty(std::unordered_map<std::string, std::string> *props, con

static std::unordered_map<std::string, std::string>* LoadPropertiesSet() {
auto * properties = new std::unordered_map<std::string, std::string>();
AddProperty(properties, rocksdb_build_git_sha);
AddProperty(properties, rocksdb_build_git_tag);
AddProperty(properties, rocksdb_build_date);
AddProperty(properties, speedb_build_git_sha);
AddProperty(properties, speedb_build_git_tag);
AddProperty(properties, speedb_build_date);
if (SPDB_BUILD_TAG[0] == '@') {
AddProperty(properties, "?");
} else {
AddProperty(properties, speedb_build_tag);
}
return properties;
}

Expand All @@ -60,14 +69,32 @@ const std::unordered_map<std::string, std::string>& GetRocksBuildProperties() {
std::string GetRocksVersionAsString(bool with_patch) {
std::string version = std::to_string(ROCKSDB_MAJOR) + "." + std::to_string(ROCKSDB_MINOR);
if (with_patch) {
return version + "." + std::to_string(ROCKSDB_PATCH);
return version + "." + ToString(ROCKSDB_PATCH);
} else {
return version;
}
}
}

std::string GetSpeedbVersionAsString(bool with_patch) {
std::string version = ToString(SPEEDB_MAJOR) + "." + ToString(SPEEDB_MINOR);
if (with_patch) {
version += "." + ToString(SPEEDB_PATCH);
// Only add a build tag if it was specified (e.g. not a release build)
if (SPDB_BUILD_TAG[0] != '\0') {
if (SPDB_BUILD_TAG[0] == '@') {
// In case build tag substitution at build time failed, add a question mark
version += "-?";
} else {
version += "-" + std::string(SPDB_BUILD_TAG);
}
}
}
return version;
}

std::string GetRocksBuildInfoAsString(const std::string& program, bool verbose) {
std::string info = program + " (SpeeDB) " + GetRocksVersionAsString(true);
std::string info = program + " (Speedb) " + GetSpeedbVersionAsString(true) +
" (" + GetRocksVersionAsString(true) + ")";
if (verbose) {
for (const auto& it : GetRocksBuildProperties()) {
info.append("\n ");
Expand Down

0 comments on commit ef570e9

Please sign in to comment.