首页 > 基础资料 博客日记
leveldb-Impl:VersionEdit.java
2023-08-03 20:20:04基础资料围观230次
文章leveldb-Impl:VersionEdit.java分享给大家,欢迎收藏Java资料网,专注分享技术知识
leveldb/VersionEdit.java at master · dain/leveldb · GitHub
public VersionEdit() { } public VersionEdit(Slice slice) { SliceInput sliceInput = slice.input(); while (sliceInput.isReadable()) { int i = VariableLengthQuantity.readVariableLengthInt(sliceInput); VersionEditTag tag = VersionEditTag.getValueTypeByPersistentId(i); tag.readValue(sliceInput, this); } }
slice的长度和tag传入versionEdit
public String getComparatorName() { return comparatorName; } public void setComparatorName(String comparatorName) { this.comparatorName = comparatorName; } public Long getLogNumber() { return logNumber; } public void setLogNumber(long logNumber) { this.logNumber = logNumber; } public Long getNextFileNumber() { return nextFileNumber; } public void setNextFileNumber(long nextFileNumber) { this.nextFileNumber = nextFileNumber; } public Long getPreviousLogNumber() { return previousLogNumber; } public void setPreviousLogNumber(long previousLogNumber) { this.previousLogNumber = previousLogNumber; } public Long getLastSequenceNumber() { return lastSequenceNumber; } public void setLastSequenceNumber(long lastSequenceNumber) { this.lastSequenceNumber = lastSequenceNumber; }
维护LastSequence、PreviousLogNumber、NextFileNumber、ComparatorName等信息。
public Map<Integer, InternalKey> getCompactPointers() { return ImmutableMap.copyOf(compactPointers); } public void setCompactPointer(int level, InternalKey key) { compactPointers.put(level, key); } public void setCompactPointers(Map<Integer, InternalKey> compactPointers) { this.compactPointers.putAll(compactPointers); }
维护CompactPointer的信息:level和Internal key,并定义批量处理操作。
public Multimap<Integer, FileMetaData> getNewFiles() { return ImmutableMultimap.copyOf(newFiles); } // Add the specified file at the specified level. // REQUIRES: This version has not been saved (see VersionSet::SaveTo) // REQUIRES: "smallest" and "largest" are smallest and largest keys in file public void addFile(int level, long fileNumber, long fileSize, InternalKey smallest, InternalKey largest) { FileMetaData fileMetaData = new FileMetaData(fileNumber, fileSize, smallest, largest); addFile(level, fileMetaData); } public void addFile(int level, FileMetaData fileMetaData) { newFiles.put(level, fileMetaData); } public void addFiles(Multimap<Integer, FileMetaData> files) { newFiles.putAll(files); }
在一个level上Add文件,包括fileMetaData,InternalKey的smallest 和 largest范围
public Multimap<Integer, Long> getDeletedFiles() { return ImmutableMultimap.copyOf(deletedFiles); } // Delete the specified "file" from the specified "level". public void deleteFile(int level, long fileNumber) { deletedFiles.put(level, fileNumber); }
delete文件就是把要删除的文件的level和fileNumber放入deletedFiles中。
public Slice encode() { DynamicSliceOutput dynamicSliceOutput = new DynamicSliceOutput(4096); for (VersionEditTag versionEditTag : VersionEditTag.values()) { versionEditTag.writeValue(dynamicSliceOutput, this); } return dynamicSliceOutput.slice(); }
对slice进行编码
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("VersionEdit"); sb.append("{comparatorName='").append(comparatorName).append('\''); sb.append(", logNumber=").append(logNumber); sb.append(", previousLogNumber=").append(previousLogNumber); sb.append(", lastSequenceNumber=").append(lastSequenceNumber); sb.append(", compactPointers=").append(compactPointers); sb.append(", newFiles=").append(newFiles); sb.append(", deletedFiles=").append(deletedFiles); sb.append('}'); return sb.toString(); }
转化为string
文章来源:https://www.cnblogs.com/yunqihao/p/16524339.html
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:jacktools123@163.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:jacktools123@163.com进行投诉反馈,一经查实,立即删除!
标签:
上一篇:JavaStudy总结
下一篇:javascript日期格式化