diff --git a/rpl/file_store.go b/rpl/file_store.go index d6b9d26..127dd19 100644 --- a/rpl/file_store.go +++ b/rpl/file_store.go @@ -30,7 +30,15 @@ const ( data: log1 data | log2 data | magic data meta: log1 pos in data | log2 pos in data + log id can not be 0, we use here for magic log + if data has no magic data, it means that we don't close replication gracefully. + so we must repair the log data + magic data = log0 data + we use table to mangage data + meta pair + + we must guarantee that the log id is monotonic increment strictly. + if log1's id is 1, log2 must be 2 */ type FileStore struct { diff --git a/rpl/file_table.go b/rpl/file_table.go index def4355..2a81ebf 100644 --- a/rpl/file_table.go +++ b/rpl/file_table.go @@ -1 +1,29 @@ package rpl + +import ( + "fmt" + "os" + "path" +) + +type table struct { + baseName string + + index int64 + + readonly bool + df *os.File + mf *os.File + + first uint64 + last uint64 +} + +func newReadTable(base string, index int64) (*table, error) { + t := new(table) + + t.baseName = path.Join(base, fmt.Sprintf("%08d", index)) + t.index = index + + return t, nil +}