Check in code for new random number generator

This commit is contained in:
2022-03-31 17:15:15 -04:00
parent 7fc6263e37
commit c48e02642a
9 changed files with 291 additions and 8 deletions

View File

@@ -19,6 +19,7 @@ IdGlobalPool::IdGlobalPool() {
salvaged_.clear();
next_batch_ = 0;
next_id_ = 0;
next_seqno_ = 0;
}
IdGlobalPool::~IdGlobalPool() {
@@ -66,6 +67,7 @@ void IdGlobalPool::salvage(int64_t batch) {
void IdGlobalPool::serialize(StreamBuffer *sb) const {
sb->write_int64(next_batch_);
sb->write_int64(next_id_);
sb->write_uint64(next_seqno_);
sb->write_uint32(salvaged_.size());
for (int64_t batch : salvaged_) {
sb->write_int64(batch);
@@ -75,6 +77,7 @@ void IdGlobalPool::serialize(StreamBuffer *sb) const {
void IdGlobalPool::deserialize(StreamBuffer *sb) {
next_batch_ = sb->read_int64();
next_id_ = sb->read_int64();
next_seqno_ = sb->read_uint64();
uint32_t salvaged_size = sb->read_uint32();
salvaged_.resize(salvaged_size);
for (int i=0; i < int(salvaged_size); i++) {
@@ -86,6 +89,7 @@ eng::string IdGlobalPool::debug_string() const {
eng::ostringstream oss;
oss << "next_batch:" << util::hex64() << next_batch_ << " ";
oss << "next_id:" << util::hex64() << next_id_ << " ";
oss << "next_seqno: " << util::hex64() << next_seqno_ << " ";
oss << "salvaged:";
for (const int64_t val : salvaged_) {
oss << " " << util::hex64() << val;
@@ -96,6 +100,7 @@ eng::string IdGlobalPool::debug_string() const {
IdPlayerPool::IdPlayerPool(IdGlobalPool *g) {
global_ = g;
fifo_capacity_ = 0;
next_seqno_ = 0;
}
IdPlayerPool::~IdPlayerPool() {
@@ -149,6 +154,7 @@ int64_t IdPlayerPool::get_one() {
void IdPlayerPool::serialize(StreamBuffer *sb) const {
sb->write_uint8(fifo_capacity_);
sb->write_uint8(ranges_.size());
sb->write_uint64(next_seqno_);
for (int64_t batch : ranges_) {
sb->write_int64(batch);
}
@@ -157,6 +163,7 @@ void IdPlayerPool::serialize(StreamBuffer *sb) const {
void IdPlayerPool::deserialize(StreamBuffer *sb) {
fifo_capacity_ = sb->read_uint8();
int ranges_size = sb->read_uint8();
next_seqno_ = sb->read_uint64();
ranges_.resize(ranges_size);
for (int i=0; i < ranges_size; i++) {
ranges_[i] = sb->read_int64();
@@ -166,6 +173,7 @@ void IdPlayerPool::deserialize(StreamBuffer *sb) {
bool IdPlayerPool::exactly_equal(const IdPlayerPool &other) const {
if (fifo_capacity_ != other.fifo_capacity_) return false;
if (ranges_.size() != other.ranges_.size()) return false;
if (next_seqno_ != other.next_seqno_) return false;
for (int i = 0; i < int(ranges_.size()); i++) {
if (ranges_[i] != other.ranges_[i]) {
return false;
@@ -190,10 +198,11 @@ void IdPlayerPool::diff(const IdPlayerPool &auth, StreamBuffer *sb) const {
return;
}
// Write the fifo capacity and nranges
// Write the fifo capacity, nranges, and next seqno
assert(auth.fifo_capacity_ != 255);
sb->write_uint8(auth.fifo_capacity_);
sb->write_uint8(auth.ranges_.size());
sb->write_uint64(auth.next_seqno_);
// Build up an index of the known IDs.
eng::map<int64_t, int> index;
@@ -225,6 +234,7 @@ void IdPlayerPool::patch(StreamBuffer *sb, DebugCollector *dbc) {
DebugLine(dbc) << "IdPlayerPool modified";
fifo_capacity_ = fifo_cap;
int nranges = sb->read_uint8();
next_seqno_ = sb->read_uint64();
eng::deque<int64_t> old = std::move(ranges_);
ranges_.clear();
for (int i = 0; i < nranges; i++) {
@@ -245,6 +255,7 @@ eng::string IdPlayerPool::debug_string() const {
if (i > 0) oss << ",";
oss << util::hex64() << ranges_[i];
}
oss << " seqno:" << util::hex64() << next_seqno_;
return oss.str();
}