作者: 韩晨旭 10225101440 李畅 10225102463
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.

35 lines
789 B

  1. #include "table/vtable_builder.h"
  2. #include "leveldb/env.h"
  3. namespace leveldb {
  4. VTableBuilder::VTableBuilder(const Options& options, WritableFile* file)
  5. : file_(file),
  6. encoder_() {}
  7. void VTableBuilder::Add(const VTableRecord& record, VTableHandle* handle) {
  8. if (!ok()) return;
  9. encoder_.Encode(record);
  10. handle->offset = file_size_;
  11. handle->size = encoder_.GetEncodedSize();
  12. file_size_ += encoder_.GetEncodedSize();
  13. status_ = file_->Append(encoder_.GetHeader().ToString() +
  14. encoder_.GetRecord().ToString());
  15. assert(ok());
  16. //TODO: meta info support in the future
  17. }
  18. Status VTableBuilder::Finish() {
  19. if (!ok()) return status();
  20. status_ = file_->Flush();
  21. return status();
  22. }
  23. void VTableBuilder::Abandon() { }
  24. } // namespace leveldb