Reputation: 19
We are using leveldb for indexing data blocks for disks and use one leveldb instance per disk. The keys for the index are The fingerprint was existing in the key for some historical reasons (not known to me) We are planning to get rid of this fingerprint suffix from the key (as we concluded that we can maintain uniqueness of the key with just inode and page_offset).
The issue is the upgrade from older version to newer version, where we need to maintain two indexes for brief time till the first index becomes free. The question is, is there a way to use the same old index and change the key size for the new key insertions and to use only for old keys ignoring the suffix part during lookups ?
Please let me know if my question is not very clear.
Upvotes: 0
Views: 300
Reputation: 4476
You can do some work on leveldb::Options.comparator
, which by default is leveldb::BytewiseComparatorImpl
.
For a example you can define a class named IgnoreSuffixComparatorImpl :
#include "leveldb/comparator.h"
class IgnoreSuffixComparatorImpl : public Comparator {
...
virtual int Compare(const Slice& a, const Slice& b) const {
return removeSuffix(a).compare(removeSuffix(b));
}
...
}
Then, when you init db, you can use the new comparator:
options.comparator = new IgnoreSuffixComparatorImpl();
s = leveldb::DB::Open(options, db_path, manifest, &db);
Upvotes: 0