@@ -147,7 +147,7 @@ class SpecialEnv : public EnvWrapper {
147147
148148 Status s = target ()->NewWritableFile (f, r);
149149 if (s.ok ()) {
150- if (strstr (f.c_str (), " .sst " ) != NULL ) {
150+ if (strstr (f.c_str (), " .ldb " ) != NULL ) {
151151 *r = new SSTableFile (this , *r);
152152 } else if (strstr (f.c_str (), " MANIFEST" ) != NULL ) {
153153 *r = new ManifestFile (this , *r);
@@ -484,6 +484,24 @@ class DBTest {
484484 }
485485 return false ;
486486 }
487+
488+ // Returns number of files renamed.
489+ int RenameLDBToSST () {
490+ std::vector<std::string> filenames;
491+ ASSERT_OK (env_->GetChildren (dbname_, &filenames));
492+ uint64_t number;
493+ FileType type;
494+ int files_renamed = 0 ;
495+ for (size_t i = 0 ; i < filenames.size (); i++) {
496+ if (ParseFileName (filenames[i], &number, &type) && type == kTableFile ) {
497+ const std::string from = TableFileName (dbname_, number);
498+ const std::string to = SSTTableFileName (dbname_, number);
499+ ASSERT_OK (env_->RenameFile (from, to));
500+ files_renamed++;
501+ }
502+ }
503+ return files_renamed;
504+ }
487505};
488506
489507TEST (DBTest, Empty) {
@@ -1632,6 +1650,22 @@ TEST(DBTest, MissingSSTFile) {
16321650 << s.ToString ();
16331651}
16341652
1653+ TEST (DBTest, StillReadSST) {
1654+ ASSERT_OK (Put (" foo" , " bar" ));
1655+ ASSERT_EQ (" bar" , Get (" foo" ));
1656+
1657+ // Dump the memtable to disk.
1658+ dbfull ()->TEST_CompactMemTable ();
1659+ ASSERT_EQ (" bar" , Get (" foo" ));
1660+ Close ();
1661+ ASSERT_GT (RenameLDBToSST (), 0 );
1662+ Options options = CurrentOptions ();
1663+ options.paranoid_checks = true ;
1664+ Status s = TryReopen (&options);
1665+ ASSERT_TRUE (s.ok ());
1666+ ASSERT_EQ (" bar" , Get (" foo" ));
1667+ }
1668+
16351669TEST (DBTest, FilesDeletedAfterCompaction) {
16361670 ASSERT_OK (Put (" foo" , " v2" ));
16371671 Compact (" a" , " z" );
0 commit comments