@@ -81,8 +81,6 @@ BlobDBImpl::BlobDBImpl(const std::string& dbname,
8181 open_file_count_(0 ),
8282 total_blob_size_(0 ),
8383 live_sst_size_(0 ),
84- fifo_eviction_seq_(0 ),
85- evict_expiration_up_to_(0 ),
8684 debug_level_(0 ) {
8785 clock_ = env_->GetSystemClock ().get ();
8886 blob_dir_ = (bdb_options_.path_relative )
@@ -277,7 +275,7 @@ Status BlobDBImpl::Open(std::vector<ColumnFamilyHandle*>* handles) {
277275 return s;
278276 }
279277
280- UpdateLiveSSTSize (WriteOptions (Env::IOActivity:: kDBOpen ) );
278+ UpdateLiveSSTSize ();
281279
282280 // Start background jobs.
283281 if (!bdb_options_.disable_background_tasks ) {
@@ -591,7 +589,6 @@ bool BlobDBImpl::MarkBlobFileObsoleteIfNeeded(
591589 assert (blob_file->Immutable ());
592590 assert (bdb_options_.enable_garbage_collection );
593591
594- // Note: FIFO eviction could have marked this file obsolete already.
595592 if (blob_file->Obsolete ()) {
596593 return true ;
597594 }
@@ -1095,11 +1092,8 @@ Status BlobDBImpl::PutBlobValue(const WriteOptions& write_options,
10951092 std::string headerbuf;
10961093 BlobLogWriter::ConstructBlobHeader (&headerbuf, key, value, expiration);
10971094
1098- // Check DB size limit before selecting blob file to
1099- // Since CheckSizeAndEvictBlobFiles() can close blob files, it needs to be
1100- // done before calling SelectBlobFile().
1101- s = CheckSizeAndEvictBlobFiles (
1102- write_options, headerbuf.size () + key.size () + value.size ());
1095+ // Check DB size limit before selecting blob file.
1096+ s = CheckDbSizeLimit (headerbuf.size () + key.size () + value.size ());
11031097 if (!s.ok ()) {
11041098 return s;
11051099 }
@@ -1187,8 +1181,6 @@ void BlobDBImpl::GetCompactionContextCommon(BlobCompactionContext* context) {
11871181 for (auto & p : blob_files_) {
11881182 context->current_blob_files .insert (p.first );
11891183 }
1190- context->fifo_eviction_seq = fifo_eviction_seq_;
1191- context->evict_expiration_up_to = evict_expiration_up_to_;
11921184}
11931185
11941186void BlobDBImpl::GetCompactionContext (BlobCompactionContext* context) {
@@ -1216,7 +1208,7 @@ void BlobDBImpl::GetCompactionContext(BlobCompactionContext* context,
12161208 }
12171209}
12181210
1219- void BlobDBImpl::UpdateLiveSSTSize (const WriteOptions& write_options ) {
1211+ void BlobDBImpl::UpdateLiveSSTSize () {
12201212 uint64_t live_sst_size = 0 ;
12211213 bool ok = GetIntProperty (DB ::Properties::kLiveSstFilesSize , &live_sst_size);
12221214 if (ok) {
@@ -1229,90 +1221,21 @@ void BlobDBImpl::UpdateLiveSSTSize(const WriteOptions& write_options) {
12291221 db_options_.info_log ,
12301222 " Failed to update total SST file size after flush or compaction." );
12311223 }
1232- {
1233- // Trigger FIFO eviction if needed.
1234- MutexLock l (&write_mutex_);
1235- Status s = CheckSizeAndEvictBlobFiles (write_options, 0 , true /* force*/ );
1236- if (s.IsNoSpace ()) {
1237- ROCKS_LOG_WARN (db_options_.info_log ,
1238- " DB grow out-of-space after SST size updated. Current live"
1239- " SST size: %" PRIu64
1240- " , current blob files size: %" PRIu64 " ." ,
1241- live_sst_size_.load (), total_blob_size_.load ());
1242- }
1243- }
12441224}
12451225
1246- Status BlobDBImpl::CheckSizeAndEvictBlobFiles (const WriteOptions& write_options,
1247- uint64_t blob_size,
1248- bool force_evict) {
1249- write_mutex_.AssertHeld ();
1250-
1251- uint64_t live_sst_size = live_sst_size_.load ();
1252- if (bdb_options_.max_db_size == 0 ||
1253- live_sst_size + total_blob_size_.load () + blob_size <=
1254- bdb_options_.max_db_size ) {
1226+ Status BlobDBImpl::CheckDbSizeLimit (uint64_t blob_size) {
1227+ if (bdb_options_.max_db_size == 0 ) {
12551228 return Status::OK ();
12561229 }
12571230
1258- if (bdb_options_.is_fifo == false ||
1259- (!force_evict && live_sst_size + blob_size > bdb_options_.max_db_size )) {
1260- // FIFO eviction is disabled, or no space to insert new blob even we evict
1261- // all blob files.
1262- return Status::NoSpace (
1263- " Write failed, as writing it would exceed max_db_size limit." );
1231+ uint64_t live_sst_size = live_sst_size_.load ();
1232+ uint64_t total_blob_size = total_blob_size_.load ();
1233+ if (live_sst_size + total_blob_size + blob_size <= bdb_options_.max_db_size ) {
1234+ return Status::OK ();
12641235 }
12651236
1266- std::vector<std::shared_ptr<BlobFile>> candidate_files;
1267- CopyBlobFiles (&candidate_files);
1268- std::sort (candidate_files.begin (), candidate_files.end (),
1269- BlobFileComparator ());
1270- fifo_eviction_seq_ = GetLatestSequenceNumber ();
1271-
1272- WriteLock l (&mutex_);
1273-
1274- while (!candidate_files.empty () &&
1275- live_sst_size + total_blob_size_.load () + blob_size >
1276- bdb_options_.max_db_size ) {
1277- std::shared_ptr<BlobFile> blob_file = candidate_files.back ();
1278- candidate_files.pop_back ();
1279- WriteLock file_lock (&blob_file->mutex_ );
1280- if (blob_file->Obsolete ()) {
1281- // File already obsoleted by someone else.
1282- assert (blob_file->Immutable ());
1283- continue ;
1284- }
1285- // FIFO eviction can evict open blob files.
1286- if (!blob_file->Immutable ()) {
1287- Status s = CloseBlobFile (write_options, blob_file);
1288- if (!s.ok ()) {
1289- return s;
1290- }
1291- }
1292- assert (blob_file->Immutable ());
1293- auto expiration_range = blob_file->GetExpirationRange ();
1294- ROCKS_LOG_INFO (db_options_.info_log ,
1295- " Evict oldest blob file since DB out of space. Current "
1296- " live SST file size: %" PRIu64 " , total blob size: %" PRIu64
1297- " , max db size: %" PRIu64 " , evicted blob file #%" PRIu64
1298- " ." ,
1299- live_sst_size, total_blob_size_.load (),
1300- bdb_options_.max_db_size , blob_file->BlobFileNumber ());
1301- ObsoleteBlobFile (blob_file, fifo_eviction_seq_, true /* update_size*/ );
1302- evict_expiration_up_to_ = expiration_range.first ;
1303- RecordTick (statistics_, BLOB_DB_FIFO_NUM_FILES_EVICTED );
1304- RecordTick (statistics_, BLOB_DB_FIFO_NUM_KEYS_EVICTED ,
1305- blob_file->BlobCount ());
1306- RecordTick (statistics_, BLOB_DB_FIFO_BYTES_EVICTED ,
1307- blob_file->GetFileSize ());
1308- TEST_SYNC_POINT (" BlobDBImpl::EvictOldestBlobFile:Evicted" );
1309- }
1310- if (live_sst_size + total_blob_size_.load () + blob_size >
1311- bdb_options_.max_db_size ) {
1312- return Status::NoSpace (
1313- " Write failed, as writing it would exceed max_db_size limit." );
1314- }
1315- return Status::OK ();
1237+ return Status::NoSpace (
1238+ " Write failed, as writing it would exceed max_db_size limit." );
13161239}
13171240
13181241Status BlobDBImpl::AppendBlob (const WriteOptions& write_options,
0 commit comments