/** * Get the metadata map. This data is for informational purposes only. The * data is subject to change in future versions. * <p> * The data in this map should not be modified (changing system data may * corrupt the store). If modifications are needed, they need be * synchronized on the store. * <p> * The metadata map contains the following entries: * <pre> * chunk.{chunkId} = {chunk metadata} * name.{name} = {mapId} * map.{mapId} = {map metadata} * root.{mapId} = {root position} * setting.storeVersion = {version} * </pre> * * @return the metadata map */ public MVMap<String, String> getMetaMap() { checkOpen(); return meta; }
/** * Force all stored changes to be written to the storage. The default * implementation calls FileChannel.force(true). */ public void sync() { checkOpen(); FileStore f = fileStore; if (f != null) { f.sync(); } }
/** * Get the set of all map names. * * @return the set of names */ public synchronized Set<String> getMapNames() { HashSet<String> set = new HashSet<>(); checkOpen(); for (Iterator<String> it = meta.keyIterator("name."); it.hasNext();) { String x = it.next(); if (!x.startsWith("name.")) { break; } set.add(x.substring("name.".length())); } return set; }
private void setWriteVersion(long version) { for (MVMap<?, ?> map : maps.values()) { map.setWriteVersion(version); } MVMap<String, String> m = meta; if (m == null) { checkOpen(); } m.setWriteVersion(version); }
/** * Update the store version. * * @param version the new store version */ public synchronized void setStoreVersion(int version) { checkOpen(); markMetaChanged(); meta.put("setting.storeVersion", Integer.toHexString(version)); }
/** * 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); }
/** * Check whether there are any unsaved changes. * * @return if there are any changes */ public boolean hasUnsavedChanges() { checkOpen(); if (metaChanged) { return true; } for (MVMap<?, ?> m : maps.values()) { if (!m.isClosed()) { long v = m.getVersion(); if (v >= 0 && v > lastStoredVersion) { return true; } } } return false; }
checkOpen(); ArrayList<Chunk> old; synchronized (this) {
/** * 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); }
private Chunk getChunkIfFound(long pos) { int chunkId = DataUtils.getPageChunkId(pos); Chunk c = chunks.get(chunkId); if (c == null) { checkOpen(); if (!Thread.holdsLock(this)) { // it could also be unsynchronized metadata // access (if synchronization on this was forgotten) throw DataUtils.newIllegalStateException( DataUtils.ERROR_CHUNK_NOT_FOUND, "Chunk {0} no longer exists", chunkId); } String s = meta.get(Chunk.getMetaKey(chunkId)); if (s == null) { return null; } c = Chunk.fromString(s); if (c.block == Long.MAX_VALUE) { throw DataUtils.newIllegalStateException( DataUtils.ERROR_FILE_CORRUPT, "Chunk {0} is invalid", chunkId); } chunks.put(c.id, c); } return c; }
checkOpen(); if (version == 0) {
/** * Remove a map. Please note rolling back this operation does not restore * the data; if you need this ability, use Map.clear(). * * @param map the map to remove */ public synchronized void removeMap(MVMap<?, ?> map) { checkOpen(); DataUtils.checkArgument(map != meta, "Removing the meta map is not allowed"); map.clear(); int id = map.getId(); String name = getMapName(id); markMetaChanged(); meta.remove(MVMap.getMapKey(id)); meta.remove("name." + name); meta.remove(MVMap.getMapRootKey(id)); maps.remove(id); }
/** * Rename a map. * * @param map the map * @param newName the new name */ public synchronized void renameMap(MVMap<?, ?> map, String newName) { checkOpen(); DataUtils.checkArgument(map != meta, "Renaming the meta map is not allowed"); int id = map.getId(); String oldName = getMapName(id); if (oldName.equals(newName)) { return; } DataUtils.checkArgument( !meta.containsKey("name." + newName), "A map named {0} already exists", newName); markMetaChanged(); String x = Integer.toHexString(id); meta.remove("name." + oldName); meta.put(MVMap.getMapKey(id), map.asString(newName)); meta.put("name." + newName, x); }
checkOpen(); if (lastChunk == null) {
checkOpen(); if (lastChunk == null || !reuseSpace) {
checkOpen(); String x = meta.get("name." + name); int id;
/** * Force all stored changes to be written to the storage. The default * implementation calls FileChannel.force(true). */ public void sync() { checkOpen(); FileStore f = fileStore; if (f != null) { f.sync(); } }
/** * Update the store version. * * @param version the new store version */ public synchronized void setStoreVersion(int version) { checkOpen(); markMetaChanged(); meta.put("setting.storeVersion", Integer.toHexString(version)); }
/** * 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); }