private MVMap<String, String> getMetaMap(long version) { Chunk c = getChunkForVersion(version); DataUtils.checkArgument(c != null, "Unknown version {0}", version); c = readChunkHeader(c.block); MVMap<String, String> oldMeta = meta.openReadOnly(); oldMeta.setRootPos(c.metaRootPos, version); return oldMeta; }
/** * Get the store version. The store version is usually used to upgrade the * structure of the store after upgrading the application. Initially the * store version is 0, until it is changed. * * @return the store version */ public int getStoreVersion() { checkOpen(); String x = meta.get("setting.storeVersion"); return x == null ? 0 : DataUtils.parseHexInt(x); }
/** * Get the name of the given map. * * @param id the map id * @return the name, or null if not found */ public synchronized String getMapName(int id) { checkOpen(); String m = meta.get(MVMap.getMapKey(id)); return m == null ? null : DataUtils.getMapName(m); }
/** * Open a temporary map. * * @param mapName the map name * @return the map */ MVMap<Object, Integer> openTempMap(String mapName) { MVMap.Builder<Object, Integer> mapBuilder = new MVMap.Builder<Object, Integer>(). keyType(dataType); return store.openMap(mapName, mapBuilder); }
/** * Store all pending changes. */ public void flush() { FileStore s = store.getFileStore(); if (s == null || s.isReadOnly()) { return; } if (!store.compact(50, 4 * 1024 * 1024)) { store.commit(); } }
/** * Open a map with the default settings. The map is automatically create if * it does not yet exist. If a map with this name is already open, this map * is returned. * * @param <K> the key type * @param <V> the value type * @param name the name of the map * @return the map */ public <K, V> MVMap<K, V> openMap(String name) { return openMap(name, new MVMap.Builder<K, V>()); }
private static long getRootPos(MVMap<String, String> map, int mapId) { String root = map.get(MVMap.getMapRootKey(mapId)); return root == null ? 0 : DataUtils.parseHexLong(root); }
/** * Remove all entries. */ @Override public synchronized void clear() { beforeWrite(); root.removeAllRecursive(); newRoot(Page.createEmpty(this, writeVersion)); }
/** * Set the position of the root page. * * @param rootPos the position, 0 for empty * @param version the version of the root */ void setRootPos(long rootPos, long version) { root = rootPos == 0 ? Page.createEmpty(this, -1) : readPage(rootPos); root.setVersion(version); }
/** * Start collecting statistics. */ public void statisticsStart() { FileStore fs = store.getFileStore(); statisticsStart = fs == null ? 0 : fs.getReadCount(); }
/** * Write a variable size integer. * * @param x the value * @return this */ public WriteBuffer putVarInt(int x) { DataUtils.writeVarInt(ensureCapacity(5), x); return this; }
private void write(long pos, ByteBuffer buffer) { try { fileStore.writeFully(pos, buffer); } catch (IllegalStateException e) { panic(e); throw e; } }
private Chunk readChunkHeader(long block) { long p = block * BLOCK_SIZE; ByteBuffer buff = fileStore.readFully(p, Chunk.MAX_HEADER_LENGTH); return Chunk.readChunkHeader(buff, p); }
/** * Write a variable size long. * * @param x the value * @return this */ public WriteBuffer putVarLong(long x) { DataUtils.writeVarLong(ensureCapacity(10), x); return this; }
/** * Write the characters of a string in a format similar to UTF-8. * * @param s the string * @param len the number of characters to write * @return this */ public WriteBuffer putStringData(String s, int len) { ByteBuffer b = ensureCapacity(3 * len); DataUtils.writeStringData(b, s, len); return this; }
/** * Remove the page. */ public void removePage() { if(isPersistent()) { long p = pos; if (p == 0) { removedInMemory = true; } map.removePage(p, memory); } }
/** * Get the position right after the last used byte. * * @return the position */ private long getFileLengthInUse() { long result = fileStore.getFileLengthInUse(); assert result == measureFileLengthInUse() : result + " != " + measureFileLengthInUse(); return result; }
/** * Mark the file as empty. */ public void clear() { freeSpace.clear(); }