fork of https://github.com/oxigraph/rocksdb and https://github.com/facebook/rocksdb for nextgraph and oxigraph
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
2.8 KiB
112 lines
2.8 KiB
11 years ago
|
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
||
|
// This source code is licensed under the BSD-style license found in the
|
||
|
// LICENSE file in the root directory of this source tree. An additional grant
|
||
|
// of patent rights can be found in the PATENTS file in the same directory.
|
||
|
//
|
||
14 years ago
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a BSD-style license that can be
|
||
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
||
|
|
||
11 years ago
|
#pragma once
|
||
10 years ago
|
#include <vector>
|
||
|
|
||
12 years ago
|
#include "rocksdb/db.h"
|
||
14 years ago
|
|
||
11 years ago
|
namespace rocksdb {
|
||
14 years ago
|
|
||
|
class SnapshotList;
|
||
|
|
||
|
// Snapshots are kept in a doubly-linked list in the DB.
|
||
14 years ago
|
// Each SnapshotImpl corresponds to a particular sequence number.
|
||
|
class SnapshotImpl : public Snapshot {
|
||
14 years ago
|
public:
|
||
|
SequenceNumber number_; // const after creation
|
||
|
|
||
10 years ago
|
virtual SequenceNumber GetSequenceNumber() const override { return number_; }
|
||
10 years ago
|
|
||
14 years ago
|
private:
|
||
|
friend class SnapshotList;
|
||
|
|
||
14 years ago
|
// SnapshotImpl is kept in a doubly-linked circular list
|
||
|
SnapshotImpl* prev_;
|
||
|
SnapshotImpl* next_;
|
||
14 years ago
|
|
||
|
SnapshotList* list_; // just for sanity checks
|
||
10 years ago
|
|
||
|
int64_t unix_time_;
|
||
14 years ago
|
};
|
||
|
|
||
|
class SnapshotList {
|
||
|
public:
|
||
|
SnapshotList() {
|
||
|
list_.prev_ = &list_;
|
||
|
list_.next_ = &list_;
|
||
12 years ago
|
list_.number_ = 0xFFFFFFFFL; // placeholder marker, for debugging
|
||
10 years ago
|
count_ = 0;
|
||
14 years ago
|
}
|
||
|
|
||
|
bool empty() const { return list_.next_ == &list_; }
|
||
14 years ago
|
SnapshotImpl* oldest() const { assert(!empty()); return list_.next_; }
|
||
|
SnapshotImpl* newest() const { assert(!empty()); return list_.prev_; }
|
||
14 years ago
|
|
||
10 years ago
|
const SnapshotImpl* New(SnapshotImpl* s, SequenceNumber seq,
|
||
|
uint64_t unix_time) {
|
||
14 years ago
|
s->number_ = seq;
|
||
10 years ago
|
s->unix_time_ = unix_time;
|
||
14 years ago
|
s->list_ = this;
|
||
|
s->next_ = &list_;
|
||
|
s->prev_ = list_.prev_;
|
||
|
s->prev_->next_ = s;
|
||
|
s->next_->prev_ = s;
|
||
10 years ago
|
count_++;
|
||
14 years ago
|
return s;
|
||
|
}
|
||
|
|
||
10 years ago
|
// Do not responsible to free the object.
|
||
14 years ago
|
void Delete(const SnapshotImpl* s) {
|
||
14 years ago
|
assert(s->list_ == this);
|
||
|
s->prev_->next_ = s->next_;
|
||
|
s->next_->prev_ = s->prev_;
|
||
10 years ago
|
count_--;
|
||
14 years ago
|
}
|
||
|
|
||
12 years ago
|
// retrieve all snapshot numbers. They are sorted in ascending order.
|
||
10 years ago
|
std::vector<SequenceNumber> GetAll() {
|
||
|
std::vector<SequenceNumber> ret;
|
||
|
if (empty()) {
|
||
|
return ret;
|
||
|
}
|
||
12 years ago
|
SnapshotImpl* s = &list_;
|
||
12 years ago
|
while (s->next_ != &list_) {
|
||
|
ret.push_back(s->next_->number_);
|
||
10 years ago
|
s = s->next_;
|
||
12 years ago
|
}
|
||
10 years ago
|
return ret;
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
// get the sequence number of the most recent snapshot
|
||
10 years ago
|
SequenceNumber GetNewest() {
|
||
12 years ago
|
if (empty()) {
|
||
|
return 0;
|
||
|
}
|
||
|
return newest()->number_;
|
||
|
}
|
||
|
|
||
10 years ago
|
int64_t GetOldestSnapshotTime() const {
|
||
|
if (empty()) {
|
||
|
return 0;
|
||
|
} else {
|
||
|
return oldest()->unix_time_;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
uint64_t count() const { return count_; }
|
||
|
|
||
14 years ago
|
private:
|
||
|
// Dummy head of doubly-linked list of snapshots
|
||
14 years ago
|
SnapshotImpl list_;
|
||
10 years ago
|
uint64_t count_;
|
||
14 years ago
|
};
|
||
|
|
||
11 years ago
|
} // namespace rocksdb
|