summaryrefslogtreecommitdiffstats
path: root/src/rocksdb/db/db_logical_block_size_cache_test.cc
blob: 13c16618e6ba5d1197bddb2970b597db57246509 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
// Copyright (c) 2020-present, Facebook, Inc.  All rights reserved.
// This source code is licensed under both the GPLv2 (found in the
// COPYING file in the root directory) and Apache 2.0 License
// (found in the LICENSE.Apache file in the root directory).

#include "test_util/testharness.h"

#ifdef OS_LINUX
#include "env/io_posix.h"
#include "rocksdb/db.h"
#include "rocksdb/env.h"

namespace ROCKSDB_NAMESPACE {
class EnvWithCustomLogicalBlockSizeCache : public EnvWrapper {
 public:
  EnvWithCustomLogicalBlockSizeCache(Env* env, LogicalBlockSizeCache* cache)
      : EnvWrapper(env), cache_(cache) {}

  Status RegisterDbPaths(const std::vector<std::string>& paths) override {
    return cache_->RefAndCacheLogicalBlockSize(paths);
  }

  Status UnregisterDbPaths(const std::vector<std::string>& paths) override {
    cache_->UnrefAndTryRemoveCachedLogicalBlockSize(paths);
    return Status::OK();
  }

 private:
  LogicalBlockSizeCache* cache_;
};

class DBLogicalBlockSizeCacheTest : public testing::Test {
 public:
  DBLogicalBlockSizeCacheTest()
      : dbname_(test::PerThreadDBPath("logical_block_size_cache_test")),
        data_path_0_(dbname_ + "/data_path_0"),
        data_path_1_(dbname_ + "/data_path_1"),
        cf_path_0_(dbname_ + "/cf_path_0"),
        cf_path_1_(dbname_ + "/cf_path_1") {
    auto get_fd_block_size = [&](int fd) { return fd; };
    auto get_dir_block_size = [&](const std::string& /*dir*/, size_t* size) {
      *size = 1024;
      return Status::OK();
    };
    cache_.reset(
        new LogicalBlockSizeCache(get_fd_block_size, get_dir_block_size));
    env_.reset(
        new EnvWithCustomLogicalBlockSizeCache(Env::Default(), cache_.get()));
  }

 protected:
  std::string dbname_;
  std::string data_path_0_;
  std::string data_path_1_;
  std::string cf_path_0_;
  std::string cf_path_1_;
  std::unique_ptr<LogicalBlockSizeCache> cache_;
  std::unique_ptr<Env> env_;
};

TEST_F(DBLogicalBlockSizeCacheTest, OpenClose) {
  // Tests that Open will cache the logical block size for data paths,
  // and Close will remove the cached sizes.
  Options options;
  options.create_if_missing = true;
  options.env = env_.get();
  options.db_paths = {{data_path_0_, 2048}, {data_path_1_, 2048}};

  for (int i = 0; i < 2; i++) {
    DB* db;
    if (!i) {
      printf("Open\n");
      ASSERT_OK(DB::Open(options, dbname_, &db));
    } else {
#ifdef ROCKSDB_LITE
      break;
#else
      printf("OpenForReadOnly\n");
      ASSERT_OK(DB::OpenForReadOnly(options, dbname_, &db));
#endif
    }
    ASSERT_EQ(2, cache_->Size());
    ASSERT_TRUE(cache_->Contains(data_path_0_));
    ASSERT_EQ(1, cache_->GetRefCount(data_path_0_));
    ASSERT_TRUE(cache_->Contains(data_path_1_));
    ASSERT_EQ(1, cache_->GetRefCount(data_path_1_));
    ASSERT_OK(db->Close());
    ASSERT_EQ(0, cache_->Size());
    delete db;
  }
  ASSERT_OK(DestroyDB(dbname_, options, {}));
}

TEST_F(DBLogicalBlockSizeCacheTest, OpenDelete) {
  // Tests that Open will cache the logical block size for data paths,
  // and delete the db pointer will remove the cached sizes.
  Options options;
  options.create_if_missing = true;
  options.env = env_.get();

  for (int i = 0; i < 2; i++) {
    DB* db;
    if (!i) {
      printf("Open\n");
      ASSERT_OK(DB::Open(options, dbname_, &db));
    } else {
#ifdef ROCKSDB_LITE
      break;
#else
      printf("OpenForReadOnly\n");
      ASSERT_OK(DB::OpenForReadOnly(options, dbname_, &db));
#endif
    }
    ASSERT_EQ(1, cache_->Size());
    ASSERT_TRUE(cache_->Contains(dbname_));
    ASSERT_EQ(1, cache_->GetRefCount(dbname_));
    delete db;
    ASSERT_EQ(0, cache_->Size());
  }
  ASSERT_OK(DestroyDB(dbname_, options, {}));
}

TEST_F(DBLogicalBlockSizeCacheTest, CreateColumnFamily) {
  // Tests that CreateColumnFamily will cache the cf_paths,
  // drop the column family handle won't drop the cache,
  // drop and then delete the column family handle will drop the cache.
  Options options;
  options.create_if_missing = true;
  options.env = env_.get();
  ColumnFamilyOptions cf_options;
  cf_options.cf_paths = {{cf_path_0_, 1024}, {cf_path_1_, 2048}};

  DB* db;
  ASSERT_OK(DB::Open(options, dbname_, &db));
  ASSERT_EQ(1, cache_->Size());
  ASSERT_TRUE(cache_->Contains(dbname_));
  ASSERT_EQ(1, cache_->GetRefCount(dbname_));

  ColumnFamilyHandle* cf = nullptr;
  ASSERT_OK(db->CreateColumnFamily(cf_options, "cf", &cf));
  ASSERT_EQ(3, cache_->Size());
  ASSERT_TRUE(cache_->Contains(dbname_));
  ASSERT_EQ(1, cache_->GetRefCount(dbname_));
  ASSERT_TRUE(cache_->Contains(cf_path_0_));
  ASSERT_EQ(1, cache_->GetRefCount(cf_path_0_));
  ASSERT_TRUE(cache_->Contains(cf_path_1_));
  ASSERT_EQ(1, cache_->GetRefCount(cf_path_1_));

  // Drop column family does not drop cache.
  ASSERT_OK(db->DropColumnFamily(cf));
  ASSERT_EQ(3, cache_->Size());
  ASSERT_TRUE(cache_->Contains(dbname_));
  ASSERT_EQ(1, cache_->GetRefCount(dbname_));
  ASSERT_TRUE(cache_->Contains(cf_path_0_));
  ASSERT_EQ(1, cache_->GetRefCount(cf_path_0_));
  ASSERT_TRUE(cache_->Contains(cf_path_1_));
  ASSERT_EQ(1, cache_->GetRefCount(cf_path_1_));

  // Delete handle will drop cache.
  ASSERT_OK(db->DestroyColumnFamilyHandle(cf));
  ASSERT_TRUE(cache_->Contains(dbname_));
  ASSERT_EQ(1, cache_->GetRefCount(dbname_));

  delete db;
  ASSERT_EQ(0, cache_->Size());
  ASSERT_OK(DestroyDB(dbname_, options, {{"cf", cf_options}}));
}

TEST_F(DBLogicalBlockSizeCacheTest, CreateColumnFamilies) {
  // To test:
  // (1) CreateColumnFamilies will cache the cf_paths in
  // DBLogicalBlockSizeCache
  // (2) Dropping column family handles associated with
  // that cf_paths won't drop the cached cf_paths
  // (3) Deleting all the column family handles associated
  //  with that cf_paths will drop the cached cf_paths

  Options options;
  options.create_if_missing = true;
  options.env = env_.get();
  ColumnFamilyOptions cf_options;
  cf_options.cf_paths = {{cf_path_0_, 1024}};

  DB* db;
  ASSERT_OK(DB::Open(options, dbname_, &db));
  ASSERT_EQ(1, cache_->Size());
  ASSERT_TRUE(cache_->Contains(dbname_));
  ASSERT_EQ(1, cache_->GetRefCount(dbname_));

  std::vector<ColumnFamilyHandle*> cfs;
  ASSERT_OK(db->CreateColumnFamilies(cf_options, {"cf1", "cf2"}, &cfs));
  ASSERT_EQ(2, cache_->Size());
  ASSERT_TRUE(cache_->Contains(dbname_));
  ASSERT_EQ(1, cache_->GetRefCount(dbname_));
  ASSERT_TRUE(cache_->Contains(cf_path_0_));
  ASSERT_EQ(2, cache_->GetRefCount(cf_path_0_));

  // Drop column family does not drop cf_path_0_'s entry from cache
  for (ColumnFamilyHandle* cf : cfs) {
    ASSERT_OK(db->DropColumnFamily(cf));
    ASSERT_EQ(2, cache_->Size());
    ASSERT_TRUE(cache_->Contains(dbname_));
    ASSERT_EQ(1, cache_->GetRefCount(dbname_));
    ASSERT_TRUE(cache_->Contains(cf_path_0_));
    ASSERT_EQ(2, cache_->GetRefCount(cf_path_0_));
  }

  // Delete one cf handle will not drop cf_path_0_'s entry from cache because
  // another handle is still referencing cf_path_0_.
  ASSERT_OK(db->DestroyColumnFamilyHandle(cfs[0]));
  ASSERT_EQ(2, cache_->Size());
  ASSERT_TRUE(cache_->Contains(dbname_));
  ASSERT_EQ(1, cache_->GetRefCount(dbname_));
  ASSERT_TRUE(cache_->Contains(cf_path_0_));

  // Delete all cf handles and ensure the ref count of cf_path_0_ in cache_
  // can be properly decreased by releasing any background reference to the
  // ColumnFamilyData during db deletion
  ASSERT_OK(db->DestroyColumnFamilyHandle(cfs[1]));
  ASSERT_TRUE(cache_->Contains(dbname_));
  ASSERT_EQ(1, cache_->GetRefCount(dbname_));
  delete db;

  // Now cf_path_0_ in cache_ has been properly decreased and cf_path_0_'s entry
  // is dropped from cache
  ASSERT_EQ(0, cache_->Size());
  ASSERT_OK(
      DestroyDB(dbname_, options, {{"cf1", cf_options}, {"cf2", cf_options}}));
}

TEST_F(DBLogicalBlockSizeCacheTest, OpenWithColumnFamilies) {
  // Tests that Open two column families with the same cf_path will cache the
  // cf_path and have 2 references to the cached size,
  // drop the column family handle won't drop the cache,
  // drop and then delete the column family handle will drop the cache.
  Options options;
  options.create_if_missing = true;
  options.env = env_.get();

  ColumnFamilyOptions cf_options;
  cf_options.cf_paths = {{cf_path_0_, 1024}};

  for (int i = 0; i < 2; i++) {
    DB* db;
    ColumnFamilyHandle* cf1 = nullptr;
    ColumnFamilyHandle* cf2 = nullptr;
    ASSERT_OK(DB::Open(options, dbname_, &db));
    ASSERT_OK(db->CreateColumnFamily(cf_options, "cf1", &cf1));
    ASSERT_OK(db->CreateColumnFamily(cf_options, "cf2", &cf2));
    ASSERT_OK(db->DestroyColumnFamilyHandle(cf1));
    ASSERT_OK(db->DestroyColumnFamilyHandle(cf2));
    delete db;
    ASSERT_EQ(0, cache_->Size());

    std::vector<ColumnFamilyHandle*> cfs;
    if (!i) {
      printf("Open\n");
      ASSERT_OK(DB::Open(options, dbname_,
                         {{"cf1", cf_options},
                          {"cf2", cf_options},
                          {"default", ColumnFamilyOptions()}},
                         &cfs, &db));
    } else {
#ifdef ROCKSDB_LITE
      break;
#else
      printf("OpenForReadOnly\n");
      ASSERT_OK(DB::OpenForReadOnly(options, dbname_,
                                    {{"cf1", cf_options},
                                     {"cf2", cf_options},
                                     {"default", ColumnFamilyOptions()}},
                                    &cfs, &db));
#endif
    }

    // Logical block sizes of dbname_ and cf_path_0_ are cached during Open.
    ASSERT_EQ(2, cache_->Size());
    ASSERT_TRUE(cache_->Contains(dbname_));
    ASSERT_EQ(1, cache_->GetRefCount(dbname_));
    ASSERT_TRUE(cache_->Contains(cf_path_0_));
    ASSERT_EQ(2, cache_->GetRefCount(cf_path_0_));

    // Drop handles won't drop the cache.
    ASSERT_OK(db->DropColumnFamily(cfs[0]));
    ASSERT_OK(db->DropColumnFamily(cfs[1]));
    ASSERT_EQ(2, cache_->Size());
    ASSERT_TRUE(cache_->Contains(dbname_));
    ASSERT_EQ(1, cache_->GetRefCount(dbname_));
    ASSERT_TRUE(cache_->Contains(cf_path_0_));
    ASSERT_EQ(2, cache_->GetRefCount(cf_path_0_));

    // Delete 1st handle won't drop the cache for cf_path_0_.
    ASSERT_OK(db->DestroyColumnFamilyHandle(cfs[0]));
    ASSERT_EQ(2, cache_->Size());
    ASSERT_TRUE(cache_->Contains(dbname_));
    ASSERT_EQ(1, cache_->GetRefCount(dbname_));
    ASSERT_TRUE(cache_->Contains(cf_path_0_));
    ASSERT_EQ(1, cache_->GetRefCount(cf_path_0_));

    // Delete 2nd handle will drop the cache for cf_path_0_.
    ASSERT_OK(db->DestroyColumnFamilyHandle(cfs[1]));
    ASSERT_EQ(1, cache_->Size());
    ASSERT_TRUE(cache_->Contains(dbname_));
    ASSERT_EQ(1, cache_->GetRefCount(dbname_));

    // Delete the default handle won't affect the cache because db still refers
    // to the default CF.
    ASSERT_OK(db->DestroyColumnFamilyHandle(cfs[2]));
    ASSERT_EQ(1, cache_->Size());
    ASSERT_TRUE(cache_->Contains(dbname_));
    ASSERT_EQ(1, cache_->GetRefCount(dbname_));

    delete db;
    ASSERT_EQ(0, cache_->Size());
  }
  ASSERT_OK(
      DestroyDB(dbname_, options, {{"cf1", cf_options}, {"cf2", cf_options}}));
}

TEST_F(DBLogicalBlockSizeCacheTest, DestroyColumnFamilyHandle) {
  // Tests that destroy column family without dropping won't drop the cache,
  // because compaction and flush might still need to get logical block size
  // when opening new files.
  Options options;
  options.create_if_missing = true;
  options.env = env_.get();
  ColumnFamilyOptions cf_options;
  cf_options.cf_paths = {{cf_path_0_, 1024}};

  DB* db;
  ASSERT_OK(DB::Open(options, dbname_, &db));
  ASSERT_EQ(1, cache_->Size());
  ASSERT_TRUE(cache_->Contains(dbname_));
  ASSERT_EQ(1, cache_->GetRefCount(dbname_));
  ColumnFamilyHandle* cf = nullptr;
  ASSERT_OK(db->CreateColumnFamily(cf_options, "cf", &cf));
  ASSERT_EQ(2, cache_->Size());
  ASSERT_TRUE(cache_->Contains(dbname_));
  ASSERT_EQ(1, cache_->GetRefCount(dbname_));
  ASSERT_TRUE(cache_->Contains(cf_path_0_));
  ASSERT_EQ(1, cache_->GetRefCount(cf_path_0_));

  // Delete handle won't drop cache.
  ASSERT_OK(db->DestroyColumnFamilyHandle(cf));
  ASSERT_EQ(2, cache_->Size());
  ASSERT_TRUE(cache_->Contains(dbname_));
  ASSERT_EQ(1, cache_->GetRefCount(dbname_));
  ASSERT_TRUE(cache_->Contains(cf_path_0_));
  ASSERT_EQ(1, cache_->GetRefCount(cf_path_0_));

  delete db;
  ASSERT_EQ(0, cache_->Size());

  // Open with column families.
  std::vector<ColumnFamilyHandle*> cfs;
  for (int i = 0; i < 2; i++) {
    if (!i) {
      printf("Open\n");
      ASSERT_OK(DB::Open(
          options, dbname_,
          {{"cf", cf_options}, {"default", ColumnFamilyOptions()}}, &cfs, &db));
    } else {
#ifdef ROCKSDB_LITE
      break;
#else
      printf("OpenForReadOnly\n");
      ASSERT_OK(DB::OpenForReadOnly(
          options, dbname_,
          {{"cf", cf_options}, {"default", ColumnFamilyOptions()}}, &cfs, &db));
#endif
    }
    // cf_path_0_ and dbname_ are cached.
    ASSERT_EQ(2, cache_->Size());
    ASSERT_TRUE(cache_->Contains(dbname_));
    ASSERT_EQ(1, cache_->GetRefCount(dbname_));
    ASSERT_TRUE(cache_->Contains(cf_path_0_));
    ASSERT_EQ(1, cache_->GetRefCount(cf_path_0_));

    // Deleting handle won't drop cache.
    ASSERT_OK(db->DestroyColumnFamilyHandle(cfs[0]));
    ASSERT_OK(db->DestroyColumnFamilyHandle(cfs[1]));
    ASSERT_EQ(2, cache_->Size());
    ASSERT_TRUE(cache_->Contains(dbname_));
    ASSERT_EQ(1, cache_->GetRefCount(dbname_));
    ASSERT_TRUE(cache_->Contains(cf_path_0_));
    ASSERT_EQ(1, cache_->GetRefCount(cf_path_0_));

    delete db;
    ASSERT_EQ(0, cache_->Size());
  }
  ASSERT_OK(DestroyDB(dbname_, options, {{"cf", cf_options}}));
}

TEST_F(DBLogicalBlockSizeCacheTest, MultiDBWithDifferentPaths) {
  // Tests the cache behavior when there are multiple DBs sharing the same env
  // with different db_paths and cf_paths.
  Options options;
  options.create_if_missing = true;
  options.env = env_.get();

  ASSERT_OK(env_->CreateDirIfMissing(dbname_));

  DB* db0;
  ASSERT_OK(DB::Open(options, data_path_0_, &db0));
  ASSERT_EQ(1, cache_->Size());
  ASSERT_TRUE(cache_->Contains(data_path_0_));

  ColumnFamilyOptions cf_options0;
  cf_options0.cf_paths = {{cf_path_0_, 1024}};
  ColumnFamilyHandle* cf0;
  ASSERT_OK(db0->CreateColumnFamily(cf_options0, "cf", &cf0));
  ASSERT_EQ(2, cache_->Size());
  ASSERT_TRUE(cache_->Contains(data_path_0_));
  ASSERT_EQ(1, cache_->GetRefCount(data_path_0_));
  ASSERT_TRUE(cache_->Contains(cf_path_0_));
  ASSERT_EQ(1, cache_->GetRefCount(cf_path_0_));

  DB* db1;
  ASSERT_OK(DB::Open(options, data_path_1_, &db1));
  ASSERT_EQ(3, cache_->Size());
  ASSERT_TRUE(cache_->Contains(data_path_0_));
  ASSERT_EQ(1, cache_->GetRefCount(data_path_0_));
  ASSERT_TRUE(cache_->Contains(cf_path_0_));
  ASSERT_EQ(1, cache_->GetRefCount(cf_path_0_));
  ASSERT_TRUE(cache_->Contains(data_path_1_));
  ASSERT_EQ(1, cache_->GetRefCount(data_path_1_));

  ColumnFamilyOptions cf_options1;
  cf_options1.cf_paths = {{cf_path_1_, 1024}};
  ColumnFamilyHandle* cf1;
  ASSERT_OK(db1->CreateColumnFamily(cf_options1, "cf", &cf1));
  ASSERT_EQ(4, cache_->Size());
  ASSERT_TRUE(cache_->Contains(data_path_0_));
  ASSERT_EQ(1, cache_->GetRefCount(data_path_0_));
  ASSERT_TRUE(cache_->Contains(cf_path_0_));
  ASSERT_EQ(1, cache_->GetRefCount(cf_path_0_));
  ASSERT_TRUE(cache_->Contains(data_path_1_));
  ASSERT_EQ(1, cache_->GetRefCount(data_path_1_));
  ASSERT_TRUE(cache_->Contains(cf_path_1_));
  ASSERT_EQ(1, cache_->GetRefCount(cf_path_1_));

  ASSERT_OK(db0->DestroyColumnFamilyHandle(cf0));
  delete db0;
  ASSERT_EQ(2, cache_->Size());
  ASSERT_TRUE(cache_->Contains(data_path_1_));
  ASSERT_EQ(1, cache_->GetRefCount(data_path_1_));
  ASSERT_TRUE(cache_->Contains(cf_path_1_));
  ASSERT_EQ(1, cache_->GetRefCount(cf_path_1_));
  ASSERT_OK(DestroyDB(data_path_0_, options, {{"cf", cf_options0}}));

  ASSERT_OK(db1->DestroyColumnFamilyHandle(cf1));
  delete db1;
  ASSERT_EQ(0, cache_->Size());
  ASSERT_OK(DestroyDB(data_path_1_, options, {{"cf", cf_options1}}));
}

TEST_F(DBLogicalBlockSizeCacheTest, MultiDBWithSamePaths) {
  // Tests the cache behavior when there are multiple DBs sharing the same env
  // with the same db_paths and cf_paths.
  Options options;
  options.create_if_missing = true;
  options.env = env_.get();
  options.db_paths = {{data_path_0_, 1024}};
  ColumnFamilyOptions cf_options;
  cf_options.cf_paths = {{cf_path_0_, 1024}};

  ASSERT_OK(env_->CreateDirIfMissing(dbname_));

  DB* db0;
  ASSERT_OK(DB::Open(options, dbname_ + "/db0", &db0));
  ASSERT_EQ(1, cache_->Size());
  ASSERT_TRUE(cache_->Contains(data_path_0_));
  ASSERT_EQ(1, cache_->GetRefCount(data_path_0_));

  ColumnFamilyHandle* cf0;
  ASSERT_OK(db0->CreateColumnFamily(cf_options, "cf", &cf0));
  ASSERT_EQ(2, cache_->Size());
  ASSERT_TRUE(cache_->Contains(data_path_0_));
  ASSERT_EQ(1, cache_->GetRefCount(data_path_0_));
  ASSERT_TRUE(cache_->Contains(cf_path_0_));
  ASSERT_EQ(1, cache_->GetRefCount(cf_path_0_));

  DB* db1;
  ASSERT_OK(DB::Open(options, dbname_ + "/db1", &db1));
  ASSERT_EQ(2, cache_->Size());
  ASSERT_TRUE(cache_->Contains(data_path_0_));
  ASSERT_EQ(2, cache_->GetRefCount(data_path_0_));
  ASSERT_TRUE(cache_->Contains(cf_path_0_));
  ASSERT_EQ(1, cache_->GetRefCount(cf_path_0_));

  ColumnFamilyHandle* cf1;
  ASSERT_OK(db1->CreateColumnFamily(cf_options, "cf", &cf1));
  ASSERT_EQ(2, cache_->Size());
  ASSERT_TRUE(cache_->Contains(data_path_0_));
  ASSERT_EQ(2, cache_->GetRefCount(data_path_0_));
  ASSERT_TRUE(cache_->Contains(cf_path_0_));
  ASSERT_EQ(2, cache_->GetRefCount(cf_path_0_));

  ASSERT_OK(db0->DestroyColumnFamilyHandle(cf0));
  delete db0;
  ASSERT_EQ(2, cache_->Size());
  ASSERT_TRUE(cache_->Contains(data_path_0_));
  ASSERT_EQ(1, cache_->GetRefCount(data_path_0_));
  ASSERT_TRUE(cache_->Contains(cf_path_0_));
  ASSERT_EQ(1, cache_->GetRefCount(cf_path_0_));
  ASSERT_OK(DestroyDB(dbname_ + "/db0", options, {{"cf", cf_options}}));

  ASSERT_OK(db1->DestroyColumnFamilyHandle(cf1));
  delete db1;
  ASSERT_EQ(0, cache_->Size());
  ASSERT_OK(DestroyDB(dbname_ + "/db1", options, {{"cf", cf_options}}));
}

}  // namespace ROCKSDB_NAMESPACE
#endif  // OS_LINUX

int main(int argc, char** argv) {
  ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}