collocatordb: distinguished read_only_access
diff --git a/collocatordb.cc b/collocatordb.cc
index e4520c0..56fc53a 100644
--- a/collocatordb.cc
+++ b/collocatordb.cc
@@ -207,10 +207,10 @@
uint64_t default_;
std::shared_ptr<DB> OpenDb(const char *dbname);
+ std::shared_ptr<DB> OpenDbForRead(const char *dbname);
public:
- Collocators(const char *db_name);
-
+ Collocators(const char *db_name, bool read_only);
~Collocators();
// public interface of Collocators.
@@ -314,10 +314,12 @@
CollocatorIterator* SeekIterator(uint64_t w1, uint64_t w2, int8_t dist);
};
- rocksdb::Collocators::Collocators(const char *db_name) {
- std::cout << "Test merge-based counters... " << db_name << "\n";
+ rocksdb::Collocators::Collocators(const char *db_name, bool read_only = false) {
// merge_option_.sync = true;
- db_ = OpenDb(db_name);
+ if(read_only)
+ db_ = OpenDbForRead(db_name);
+ else
+ db_ = OpenDb(db_name);
assert(db_);
uint64_t one = 1;
EncodeFixed64(_one, one);
@@ -336,8 +338,20 @@
inc(encodeCollocation(w1, w2, dist));
}
+ std::shared_ptr<DB> rocksdb::Collocators::OpenDbForRead(const char *name) {
+ DB* db;
+ Options options;
+ ostringstream dbname;
+ dbname << name << ".rocksdb";
+ auto s = DB::OpenForReadOnly(options, dbname.str(), &db);
+ if (!s.ok()) {
+ std::cerr << s.ToString() << std::endl;
+ assert(false);
+ }
+ return std::shared_ptr<DB>(db);
+ }
+
std::shared_ptr<DB> rocksdb::Collocators::OpenDb(const char *dbname) {
- std::cout << "Test merge-based counters... " << dbname << "\n";
DB* db;
Options options;
@@ -526,6 +540,10 @@
return new rocksdb::Collocators(dbname);
}
+ COLLOCATORS *open_collocators_for_read(char *dbname) {
+ return new rocksdb::Collocators(dbname, true);
+ }
+
void inc_collocators(COLLOCATORS *db, uint32_t w1, uint32_t w2, int8_t dist) {
db->inc(w1, w2, dist);
}