leveldb: change the table file extension from .sst to .ldb, as per

the C++ leveldb project.

https://groups.google.com/forum/#!topic/leveldb/u9izbG-pDis

R=bradfitz, adg
CC=golang-dev
https://codereview.appspot.com/20170043
This commit is contained in:
Nigel Tao 2013-11-01 12:48:45 +11:00
Родитель b173038db4
Коммит c6c9caddd9
5 изменённых файлов: 21 добавлений и 7 удалений

Просмотреть файл

@ -644,7 +644,7 @@ func TestCompaction(t *testing.T) {
t.Errorf("%q: mem: got %q, want %q", tc.key, gotMem, tc.wantMem) t.Errorf("%q: mem: got %q, want %q", tc.key, gotMem, tc.wantMem)
} }
if gotDisk != tc.wantDisk { if gotDisk != tc.wantDisk {
t.Errorf("%q: sst: got %q, want %q", tc.key, gotDisk, tc.wantDisk) t.Errorf("%q: ldb: got %q, want %q", tc.key, gotDisk, tc.wantDisk)
} }
} }

Просмотреть файл

@ -20,6 +20,7 @@ const (
fileTypeLog fileType = iota fileTypeLog fileType = iota
fileTypeLock fileTypeLock
fileTypeTable fileTypeTable
fileTypeOldFashionedTable
fileTypeManifest fileTypeManifest
fileTypeCurrent fileTypeCurrent
) )
@ -34,6 +35,8 @@ func dbFilename(dirname string, fileType fileType, fileNum uint64) string {
case fileTypeLock: case fileTypeLock:
return fmt.Sprintf("%s%cLOCK", dirname, os.PathSeparator) return fmt.Sprintf("%s%cLOCK", dirname, os.PathSeparator)
case fileTypeTable: case fileTypeTable:
return fmt.Sprintf("%s%c%06d.ldb", dirname, os.PathSeparator, fileNum)
case fileTypeOldFashionedTable:
return fmt.Sprintf("%s%c%06d.sst", dirname, os.PathSeparator, fileNum) return fmt.Sprintf("%s%c%06d.sst", dirname, os.PathSeparator, fileNum)
case fileTypeManifest: case fileTypeManifest:
return fmt.Sprintf("%s%cMANIFEST-%06d", dirname, os.PathSeparator, fileNum) return fmt.Sprintf("%s%cMANIFEST-%06d", dirname, os.PathSeparator, fileNum)
@ -66,10 +69,12 @@ func parseDBFilename(filename string) (fileType fileType, fileNum uint64, ok boo
break break
} }
switch filename[i+1:] { switch filename[i+1:] {
case "ldb":
return fileTypeTable, u, true
case "log": case "log":
return fileTypeLog, u, true return fileTypeLog, u, true
case "sst": case "sst":
return fileTypeTable, u, true return fileTypeOldFashionedTable, u, true
} }
} }
return 0, 0, false return 0, 0, false

Просмотреть файл

@ -16,7 +16,9 @@ func TestParseDBFilename(t *testing.T) {
"000000..log": false, "000000..log": false,
"a000000.log": false, "a000000.log": false,
"abcdef.log": false, "abcdef.log": false,
"000001.sst": true, "000001ldb": false,
"000001.ldb": true,
"000002.sst": true,
"CURRENT": true, "CURRENT": true,
"CURRaNT": false, "CURRaNT": false,
"LOCK": true, "LOCK": true,
@ -42,9 +44,10 @@ func TestFilenameRoundTrip(t *testing.T) {
fileTypeCurrent: false, fileTypeCurrent: false,
fileTypeLock: false, fileTypeLock: false,
// The remaining file types are numbered. // The remaining file types are numbered.
fileTypeLog: true, fileTypeLog: true,
fileTypeManifest: true, fileTypeManifest: true,
fileTypeTable: true, fileTypeOldFashionedTable: true,
fileTypeTable: true,
} }
for fileType, numbered := range testCases { for fileType, numbered := range testCases {
fileNums := []uint64{0} fileNums := []uint64{0}

Просмотреть файл

@ -637,7 +637,7 @@ func (d *DB) deleteObsoleteFiles() {
keep = fileNum >= logNumber keep = fileNum >= logNumber
case fileTypeManifest: case fileTypeManifest:
keep = fileNum >= manifestFileNumber keep = fileNum >= manifestFileNumber
case fileTypeTable: case fileTypeTable, fileTypeOldFashionedTable:
_, keep = liveFileNums[fileNum] _, keep = liveFileNums[fileNum]
} }
if keep { if keep {

Просмотреть файл

@ -5,6 +5,7 @@
package leveldb package leveldb
import ( import (
"os"
"sync" "sync"
"code.google.com/p/leveldb-go/leveldb/db" "code.google.com/p/leveldb-go/leveldb/db"
@ -148,7 +149,12 @@ type tableCacheNode struct {
} }
func (n *tableCacheNode) load(c *tableCache) { func (n *tableCacheNode) load(c *tableCache) {
// Try opening the fileTypeTable first. If that file doesn't exist,
// fall back onto the fileTypeOldFashionedTable.
f, err := c.fs.Open(dbFilename(c.dirname, fileTypeTable, n.fileNum)) f, err := c.fs.Open(dbFilename(c.dirname, fileTypeTable, n.fileNum))
if os.IsNotExist(err) {
f, err = c.fs.Open(dbFilename(c.dirname, fileTypeOldFashionedTable, n.fileNum))
}
if err != nil { if err != nil {
n.result <- tableReaderOrError{err: err} n.result <- tableReaderOrError{err: err}
return return