cyq há 4 meses
ascendente
cometimento
c2b62825d1
4 ficheiros alterados com 48 adições e 0 eliminações
  1. +11
    -0
      fielddb/field_db.cpp
  2. +4
    -0
      fielddb/field_db.h
  3. +13
    -0
      fielddb/request.cpp
  4. +20
    -0
      fielddb/request.h

+ 11
- 0
fielddb/field_db.cpp Ver ficheiro

@ -382,6 +382,17 @@ void FieldDB::ReleaseSnapshot(const Snapshot *snapshot) {
kvDB_->ReleaseSnapshot(snapshot); kvDB_->ReleaseSnapshot(snapshot);
} }
const XSnapshot * FieldDB::GetXSnapshot() {
SnapshotReq req(&mutex_);
HandleRequest(req, WriteOptions());
return req.xSnapshot;
}
void FieldDB::ReleaseXSnapshot(const XSnapshot *xsnapshot) {
kvDB_->ReleaseSnapshot(xsnapshot->kv_snapshot);
indexDB_->ReleaseSnapshot(xsnapshot->index_snapshot);
}
bool FieldDB::GetProperty(const Slice &property, std::string *value) { bool FieldDB::GetProperty(const Slice &property, std::string *value) {
return kvDB_->GetProperty(property, value) | indexDB_->GetProperty(property, value); return kvDB_->GetProperty(property, value) | indexDB_->GetProperty(property, value);
} }

+ 4
- 0
fielddb/field_db.h Ver ficheiro

@ -35,6 +35,7 @@ public:
friend class iDeleteReq; friend class iDeleteReq;
friend class DeleteReq; friend class DeleteReq;
friend class BatchReq; friend class BatchReq;
friend class SnapshotReq;
//FieldDB *db = new FieldDB()openDB *db //FieldDB *db = new FieldDB()openDB *db
FieldDB() : indexDB_(nullptr), kvDB_(nullptr), metaDB_(nullptr) {}; FieldDB() : indexDB_(nullptr), kvDB_(nullptr), metaDB_(nullptr) {};
@ -60,6 +61,9 @@ public:
// //
IndexStatus GetIndexStatus(const std::string &fieldName); IndexStatus GetIndexStatus(const std::string &fieldName);
const XSnapshot* GetXSnapshot();
void ReleaseXSnapshot(const XSnapshot* xsnapshot);
static Status OpenFieldDB(Options& options,const std::string& name,FieldDB** dbptr); static Status OpenFieldDB(Options& options,const std::string& name,FieldDB** dbptr);
private: private:

+ 13
- 0
fielddb/request.cpp Ver ficheiro

@ -432,5 +432,18 @@ void BatchReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch,
//DB->construct_BatchReq_elapsed += DB->env_->NowMicros() - start_; //DB->construct_BatchReq_elapsed += DB->env_->NowMicros() - start_;
} }
void SnapshotReq::Prepare(FieldDB *DB) {
DB->index_mu.AssertHeld();
for(auto [_,pair] : DB->index_) {
auto [status,req] = pair;
if(status == Creating || status == Deleting) {
req->PendReq(this);
return;
}
}
xSnapshot = new XSnapshot(DB->kvDB_->GetSnapshot(),DB->indexDB_->GetSnapshot());
done = true;
}
} // namespace fielddb } // namespace fielddb

+ 20
- 0
fielddb/request.h Ver ficheiro

@ -1,5 +1,6 @@
#include <deque> #include <deque>
#include <string> #include <string>
#include "leveldb/db.h"
#include "leveldb/slice.h" #include "leveldb/slice.h"
#include "leveldb/status.h" #include "leveldb/status.h"
#include "leveldb/write_batch.h" #include "leveldb/write_batch.h"
@ -164,6 +165,25 @@ public:
// std::deque<FieldArray> fa_buf; // std::deque<FieldArray> fa_buf;
}; };
class SnapshotReq;
class XSnapshot {
friend class SnapshotReq;
public:
XSnapshot(const Snapshot *kv,const Snapshot *index)
: kv_snapshot(kv), index_snapshot(index) {}
const leveldb::Snapshot *kv_snapshot;
const leveldb::Snapshot *index_snapshot;
};
class SnapshotReq : public Request {
public:
SnapshotReq(port::Mutex *mu):Request(iCreateReq_t, mu) { };
void Prepare(FieldDB *DB);
XSnapshot *xSnapshot;
};
} }
#endif #endif

||||||
x
 
000:0
Carregando…
Cancelar
Guardar