Skip to content

Commit

Permalink
[BP] MB-18158 Use old file's version info during the migration of KVS…
Browse files Browse the repository at this point in the history
… header info

- When we read KVS header info from the old file, we should use the old
file's version info, not the latest magic.

- As Sherlock branch uses the oldest magic number (MAGIC_000), we get
rid of the code block that denies opening old files.

Change-Id: I322309c0993e2d1fada9fdfb81b79be5a9c52630
  • Loading branch information
greensky00 authored and chiyoung committed Mar 12, 2016
1 parent 4341531 commit 793f17f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
17 changes: 3 additions & 14 deletions src/filemgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,6 @@ static fdb_status _filemgr_read_header(struct filemgr *file,

if (ver_is_valid_magic(magic)) {

if (ver_is_magic_000(magic)) {
// Deny MAGIC_000 file as it doesn't have any version info
status = FDB_RESULT_FILE_VERSION_NOT_SUPPORTED;
const char *msg = "Denied reading a database file '%s': "
"too old version\n";
fdb_log(log_callback, status, msg, file->filename);
break;
}

memcpy(&len,
buf + file->blocksize - BLK_MARKER_SIZE -
sizeof(magic) - sizeof(len),
Expand All @@ -434,7 +425,7 @@ static fdb_status _filemgr_read_header(struct filemgr *file,
} else {
status = FDB_RESULT_SUCCESS;

file->header.data = (void *)malloc(len);
file->header.data = (void *)malloc(file->blocksize);

memcpy(file->header.data, buf, len);
memcpy(&file->header.revnum, buf + len,
Expand Down Expand Up @@ -923,9 +914,7 @@ uint64_t filemgr_update_header(struct filemgr *file, void *buf, size_t len)
spin_lock(&file->lock);

if (file->header.data == NULL) {
file->header.data = (void *)malloc(len);
}else if (file->header.size < len){
file->header.data = (void *)realloc(file->header.data, len);
file->header.data = (void *)malloc(file->blocksize);
}
memcpy(file->header.data, buf, len);
file->header.size = len;
Expand Down Expand Up @@ -2263,7 +2252,7 @@ char *filemgr_redirect_old_file(struct filemgr *very_old_file,
// very_old_file, maybe reallocate DB header buf to accomodate bigger value
if (new_header_len > old_header_len) {
very_old_file->header.data = realloc(very_old_file->header.data,
new_header_len);
new_file->blocksize);
}
very_old_file->new_file = new_file; // Re-direct very_old_file to new_file
past_filename = redirect_header_func(very_old_file,
Expand Down
2 changes: 1 addition & 1 deletion src/kv_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ void fdb_kvs_header_copy(fdb_kvs_handle *handle,
_fdb_kvs_header_create(&kv_header);
// read from 'handle->dhandle', and import into 'new_file'
fdb_kvs_header_read(kv_header, handle->dhandle,
handle->kv_info_offset, ver_get_latest_magic(), false);
handle->kv_info_offset, handle->file->version, false);

// write KV header in 'new_file' using 'new_dhandle'
uint64_t new_kv_info_offset;
Expand Down
2 changes: 1 addition & 1 deletion src/version.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ size_t ver_get_last_wal_flush_hdr_off(filemgr_magic_t magic) {
const char* ver_get_version_string(filemgr_magic_t magic) {
switch (magic) {
case FILEMGR_MAGIC_000:
return "ForestDB pre-v1.x format";
return "ForestDB v1.x format";
case FILEMGR_MAGIC_001:
return "ForestDB v1.x format";
case FILEMGR_MAGIC_002:
Expand Down
7 changes: 5 additions & 2 deletions tests/anomaly/fdb_anomaly_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -783,8 +783,11 @@ void read_old_file()

// reopen
s = fdb_open(&dbfile, "anomaly_test1", &config);
// should return version error
TEST_CHK(s == FDB_RESULT_FILE_VERSION_NOT_SUPPORTED);
// successfully read
TEST_CHK(s == FDB_RESULT_SUCCESS);

s = fdb_close(dbfile);
TEST_CHK(s == FDB_RESULT_SUCCESS);

s = fdb_shutdown();
memleak_end();
Expand Down

0 comments on commit 793f17f

Please sign in to comment.