Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support .sst and .ldb extension #124

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions leveldb/src/main/java/org/iq80/leveldb/impl/Filename.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public static String logFileName(long number)
* Return the name of the sstable with the specified number.
*/
public static String tableFileName(long number)
{
return makeFileName(number, "ldb");
}

public static String sstTableFileName(long number)
{
return makeFileName(number, "sst");
}
Expand Down Expand Up @@ -149,6 +154,10 @@ else if (fileName.endsWith(".sst")) {
long fileNumber = Long.parseLong(removeSuffix(fileName, ".sst"));
return new FileInfo(FileType.TABLE, fileNumber);
}
else if (fileName.endsWith(".ldb")) {
long fileNumber = Long.parseLong(removeSuffix(fileName, ".ldb"));
return new FileInfo(FileType.TABLE, fileNumber);
}
else if (fileName.endsWith(".dbtmp")) {
long fileNumber = Long.parseLong(removeSuffix(fileName, ".dbtmp"));
return new FileInfo(FileType.TEMP, fileNumber);
Expand Down
4 changes: 4 additions & 0 deletions leveldb/src/main/java/org/iq80/leveldb/impl/TableCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ private TableAndFile(File databaseDir, long fileNumber, UserComparator userCompa
{
String tableFileName = Filename.tableFileName(fileNumber);
File tableFile = new File(databaseDir, tableFileName);
if (!tableFile.exists()) {
tableFileName = Filename.sstTableFileName(fileNumber);
tableFile = new File(databaseDir, tableFileName);
}
FileInputStream fis = null;
try {
fis = new FileInputStream(tableFile);
Expand Down
30 changes: 30 additions & 0 deletions leveldb/src/test/java/org/iq80/leveldb/impl/DbImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import static org.iq80.leveldb.table.BlockHelper.beforeString;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
Expand Down Expand Up @@ -188,6 +189,35 @@ public void testGetFromVersions()
assertEquals(db.get("foo"), "v1");
}

@Test
public void testFileExtensionCompatible()
throws Exception
{
DbStringWrapper db = new DbStringWrapper(new Options(), databaseDir);
db.put("foo", "v1");
db.compactMemTable();
db.put("bar", "v1");
db.compactMemTable();
db.put("xvf", "v1");
db.compactMemTable();
ImmutableList<File> files = FileUtils.listFiles(databaseDir);
for (File file : files) {
Filename.FileInfo fileInfo = Filename.parseFileName(file);
assertNotNull(fileInfo);

if (fileInfo.getFileType().equals(Filename.FileType.TABLE)) {
assertTrue(file.getName().endsWith(".ldb"));
long fileNumber = fileInfo.getFileNumber();
File newFile = new File(databaseDir, Filename.sstTableFileName(fileNumber));
file.renameTo(newFile);
}
}
db.reopen();
assertEquals(db.get("foo"), "v1");
assertEquals(db.get("bar"), "v1");
assertEquals(db.get("xvf"), "v1");
}

@Test
public void testGetSnapshot()
throws Exception
Expand Down