提交 d378a757 authored 作者: Thomas Mueller's avatar Thomas Mueller

Consistently use the term "store header"

上级 42b11b0d
...@@ -203,7 +203,7 @@ public class MVStore { ...@@ -203,7 +203,7 @@ public class MVStore {
private final ConcurrentHashMap<Integer, MVMap<?, ?>> maps = private final ConcurrentHashMap<Integer, MVMap<?, ?>> maps =
new ConcurrentHashMap<Integer, MVMap<?, ?>>(); new ConcurrentHashMap<Integer, MVMap<?, ?>>();
private HashMap<String, Object> fileHeader = New.hashMap(); private HashMap<String, Object> storeHeader = New.hashMap();
private WriteBuffer writeBuffer; private WriteBuffer writeBuffer;
...@@ -342,13 +342,13 @@ public class MVStore { ...@@ -342,13 +342,13 @@ public class MVStore {
if (fileStore.size() == 0) { if (fileStore.size() == 0) {
creationTime = getTime(); creationTime = getTime();
lastCommitTime = creationTime; lastCommitTime = creationTime;
fileHeader.put("H", 2); storeHeader.put("H", 2);
fileHeader.put("blockSize", BLOCK_SIZE); storeHeader.put("blockSize", BLOCK_SIZE);
fileHeader.put("format", FORMAT_WRITE); storeHeader.put("format", FORMAT_WRITE);
fileHeader.put("created", creationTime); storeHeader.put("created", creationTime);
writeFileHeader(); writeStoreHeader();
} else { } else {
readFileHeader(); readStoreHeader();
} }
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
panic(e); panic(e);
...@@ -548,7 +548,7 @@ public class MVStore { ...@@ -548,7 +548,7 @@ public class MVStore {
metaChanged = true; metaChanged = true;
} }
private synchronized void readFileHeader() { private synchronized void readStoreHeader() {
boolean validHeader = false; boolean validHeader = false;
// we don't know yet which chunk and version are the newest // we don't know yet which chunk and version are the newest
long newestVersion = -1; long newestVersion = -1;
...@@ -583,7 +583,7 @@ public class MVStore { ...@@ -583,7 +583,7 @@ public class MVStore {
long version = DataUtils.readHexLong(m, "version", 0); long version = DataUtils.readHexLong(m, "version", 0);
if (version > newestVersion) { if (version > newestVersion) {
newestVersion = version; newestVersion = version;
fileHeader.putAll(m); storeHeader.putAll(m);
chunkBlock = DataUtils.readHexLong(m, "block", 0); chunkBlock = DataUtils.readHexLong(m, "block", 0);
creationTime = DataUtils.readHexLong(m, "created", 0); creationTime = DataUtils.readHexLong(m, "created", 0);
validHeader = true; validHeader = true;
...@@ -597,7 +597,7 @@ public class MVStore { ...@@ -597,7 +597,7 @@ public class MVStore {
DataUtils.ERROR_FILE_CORRUPT, DataUtils.ERROR_FILE_CORRUPT,
"Store header is corrupt: {0}", fileStore); "Store header is corrupt: {0}", fileStore);
} }
long format = DataUtils.readHexLong(fileHeader, "format", 1); long format = DataUtils.readHexLong(storeHeader, "format", 1);
if (format > FORMAT_WRITE && !fileStore.isReadOnly()) { if (format > FORMAT_WRITE && !fileStore.isReadOnly()) {
throw DataUtils.newIllegalStateException( throw DataUtils.newIllegalStateException(
DataUtils.ERROR_UNSUPPORTED_FORMAT, DataUtils.ERROR_UNSUPPORTED_FORMAT,
...@@ -606,7 +606,7 @@ public class MVStore { ...@@ -606,7 +606,7 @@ public class MVStore {
"and the file was not opened in read-only mode", "and the file was not opened in read-only mode",
format, FORMAT_WRITE); format, FORMAT_WRITE);
} }
format = DataUtils.readHexLong(fileHeader, "formatRead", format); format = DataUtils.readHexLong(storeHeader, "formatRead", format);
if (format > FORMAT_READ) { if (format > FORMAT_READ) {
throw DataUtils.newIllegalStateException( throw DataUtils.newIllegalStateException(
DataUtils.ERROR_UNSUPPORTED_FORMAT, DataUtils.ERROR_UNSUPPORTED_FORMAT,
...@@ -630,7 +630,7 @@ public class MVStore { ...@@ -630,7 +630,7 @@ public class MVStore {
// the system time was set to the past: // the system time was set to the past:
// we change the creation time // we change the creation time
creationTime = now; creationTime = now;
fileHeader.put("created", creationTime); storeHeader.put("created", creationTime);
} }
Chunk footer = readChunkFooter(fileStore.size()); Chunk footer = readChunkFooter(fileStore.size());
...@@ -748,14 +748,14 @@ public class MVStore { ...@@ -748,14 +748,14 @@ public class MVStore {
return null; return null;
} }
private void writeFileHeader() { private void writeStoreHeader() {
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
if (lastChunk != null) { if (lastChunk != null) {
fileHeader.put("block", lastChunk.block); storeHeader.put("block", lastChunk.block);
fileHeader.put("chunk", lastChunk.id); storeHeader.put("chunk", lastChunk.id);
fileHeader.put("version", lastChunk.version); storeHeader.put("version", lastChunk.version);
} }
DataUtils.appendMap(buff, fileHeader); DataUtils.appendMap(buff, storeHeader);
byte[] bytes = buff.toString().getBytes(DataUtils.LATIN); byte[] bytes = buff.toString().getBytes(DataUtils.LATIN);
int checksum = DataUtils.getFletcher32(bytes, bytes.length); int checksum = DataUtils.getFletcher32(bytes, bytes.length);
DataUtils.appendMap(buff, "fletcher", checksum); DataUtils.appendMap(buff, "fletcher", checksum);
...@@ -1118,28 +1118,28 @@ public class MVStore { ...@@ -1118,28 +1118,28 @@ public class MVStore {
write(filePos, buff.getBuffer()); write(filePos, buff.getBuffer());
releaseWriteBuffer(buff); releaseWriteBuffer(buff);
// whether we need to write the file header // whether we need to write the store header
boolean needHeader = false; boolean writeStoreHeader = false;
if (!storeAtEndOfFile) { if (!storeAtEndOfFile) {
if (lastChunk == null) { if (lastChunk == null) {
needHeader = true; writeStoreHeader = true;
} else if (lastChunk.next != c.block) { } else if (lastChunk.next != c.block) {
// the last prediction did not matched // the last prediction did not matched
needHeader = true; writeStoreHeader = true;
} else { } else {
long headerVersion = DataUtils.readHexLong( long headerVersion = DataUtils.readHexLong(
fileHeader, "version", 0); storeHeader, "version", 0);
if (lastChunk.version - headerVersion > 20) { if (lastChunk.version - headerVersion > 20) {
// we write after at least 20 entries // we write after at least 20 entries
needHeader = true; writeStoreHeader = true;
} else { } else {
int chunkId = DataUtils.readHexInt(fileHeader, "chunk", 0); int chunkId = DataUtils.readHexInt(storeHeader, "chunk", 0);
while (true) { while (true) {
Chunk old = chunks.get(chunkId); Chunk old = chunks.get(chunkId);
if (old == null) { if (old == null) {
// one of the chunks in between // one of the chunks in between
// was removed // was removed
needHeader = true; writeStoreHeader = true;
break; break;
} }
if (chunkId == lastChunk.id) { if (chunkId == lastChunk.id) {
...@@ -1152,11 +1152,11 @@ public class MVStore { ...@@ -1152,11 +1152,11 @@ public class MVStore {
} }
lastChunk = c; lastChunk = c;
if (needHeader) { if (writeStoreHeader) {
writeFileHeader(); writeStoreHeader();
} }
if (!storeAtEndOfFile) { if (!storeAtEndOfFile) {
// may only shrink after the file header was written // may only shrink after the store header was written
shrinkFileIfPossible(1); shrinkFileIfPossible(1);
} }
...@@ -2213,8 +2213,8 @@ public class MVStore { ...@@ -2213,8 +2213,8 @@ public class MVStore {
releaseWriteBuffer(buff); releaseWriteBuffer(buff);
lastChunk = chunks.get(lastChunk.id - 1); lastChunk = chunks.get(lastChunk.id - 1);
} }
writeFileHeader(); writeStoreHeader();
readFileHeader(); readStoreHeader();
} }
for (MVMap<?, ?> m : New.arrayList(maps.values())) { for (MVMap<?, ?> m : New.arrayList(maps.values())) {
int id = m.getId(); int id = m.getId();
...@@ -2285,7 +2285,7 @@ public class MVStore { ...@@ -2285,7 +2285,7 @@ public class MVStore {
* @return the store header * @return the store header
*/ */
public Map<String, Object> getStoreHeader() { public Map<String, Object> getStoreHeader() {
return fileHeader; return storeHeader;
} }
private void checkOpen() { private void checkOpen() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论