collocatordb: distinguished read_only_access
diff --git a/c_testanalysis.c b/c_testanalysis.c
index 6843480..5a660cb 100644
--- a/c_testanalysis.c
+++ b/c_testanalysis.c
@@ -28,9 +28,9 @@
}
int main() {
- COLLOCATORS *cdb = open_collocators("/vol/work/kupietz/Work2/kl/trunk/Analysemethoden/wang2vec/sampledb");
+ COLLOCATORS *cdb = open_collocators_for_read("/vol/work/kupietz/Work2/kl/trunk/Analysemethoden/wang2vec/sample");
read_vocab("/vol/work/kupietz/Work2/kl/trunk/Analysemethoden/wang2vec/sample.vocab");
- for(int i=500; i < 600; i++)
+ for(int i=100; i < 1000; i++)
get_collocators(cdb, i, vocab, total);
printf("%s\n", get_collocators_as_json(cdb, 500, vocab, total));
return 0;
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);
}
diff --git a/collocatordb.h b/collocatordb.h
index 95848a3..b370aae 100644
--- a/collocatordb.h
+++ b/collocatordb.h
@@ -50,6 +50,7 @@
#endif
extern COLLOCATORS *open_collocators(char *s);
+extern COLLOCATORS *open_collocators_for_read(char *s);
extern void inc_collocators(COLLOCATORS *db, uint64_t w1, uint64_t w2, int8_t dist);
extern void dump_collocators(COLLOCATORS *db, uint32_t w1, uint32_t w2, int8_t dist);
extern void get_collocators(COLLOCATORS *db, uint32_t w1, vocab_entry *vocab, uint64_t total);