leveldb写回隔离 P>如果我通过一个WrimePoT来编写很多更改,那么有一个保证,即另一个线程不会在写入磁盘的过程中读取,并结束一些新的值和一些旧的(即将被修改)?< /P>

leveldb写回隔离 P>如果我通过一个WrimePoT来编写很多更改,那么有一个保证,即另一个线程不会在写入磁盘的过程中读取,并结束一些新的值和一些旧的(即将被修改)?< /P>,leveldb,Leveldb,文档中说WriteBatch是原子的(全有或全无),但隔离又如何呢?隔离是有保证的。 请看下面的代码: WriteBatch* updates = BuildBatchGroup(&last_writer); WriteBatchInternal::SetSequence(updates, last_sequence + 1); last_sequence += WriteBatchInternal::Count(updates); // Add to log and apply to

文档中说WriteBatch是原子的(全有或全无),但隔离又如何呢?

隔离是有保证的。

请看下面的代码:

WriteBatch* updates = BuildBatchGroup(&last_writer);
WriteBatchInternal::SetSequence(updates, last_sequence + 1);
last_sequence += WriteBatchInternal::Count(updates);

// Add to log and apply to memtable.  We can release the lock
// during this phase since &w is currently responsible for logging
// and protects against concurrent loggers and concurrent writes
// into mem_.
{
  mutex_.Unlock();
  status = log_->AddRecord(WriteBatchInternal::Contents(updates));
  bool sync_error = false;
  if (status.ok() && options.sync) {
    status = logfile_->Sync();
    if (!status.ok()) {
      sync_error = true;
    }
  }
  if (status.ok()) {
    status = WriteBatchInternal::InsertInto(updates, mem_);
  }
  mutex_.Lock();
  if (sync_error) {
    // The state of the log file is indeterminate: the log record we
    // just added may or may not show up when the DB is re-opened.
    // So we force the DB into a mode where all future writes fail.
    RecordBackgroundError(status);
  }
}
if (updates == tmp_batch_) tmp_batch_->Clear();

versions_->SetLastSequence(last_sequence);

这是写批处理的过程,它应用于
[最后一个\u序列+1,最后一个\u序列+计数(更新)]
,并将在所有更新操作完成后应用该序列。这意味着读取操作可以在批量提交到wal和memtable之后获得sequence=
last\u sequence+Count(updates)

嗯,在另一个例子中得到了矛盾的答案:“…Get/Scan调用将拾取所有数据,直到指定的序列号…”你可以在那里开始辩论,以便确定真相:)哈,我研究过了,似乎我们在这里得到的分歧是,更新有相同的序列或不同的序列:……我稍后再讨论……考虑下面的情况:<代码> Logi> > AdScript < /COD>成功和<代码> WrimeBuffiN::InsertInto < /COD>失败,数据库将是什么状态?
Write
接口将返回失败状态,memtable将包含不完整或没有写回的记录,但日志文件将包含所有记录,并且序列将增加。我认为日志文件不应该应用新记录,但它是如何做到的?@jiafengfu根据代码,我们忽略了硬件ram错误WriteBatchInternal::InsertInto“仅当writebatch的格式错误时才会失败,在“DBImpl::RecoverLogFile”中,它以相同的方式失败。