public SpatialDataType(int dimensions) { // Because of how we are storing the // min-max-flag in the read/write method // the number of dimensions must be < 32. DataUtils.checkArgument( dimensions >= 1 && dimensions < 32, "Dimensions must be between 1 and 31, is {0}", dimensions); this.dimensions = dimensions; }
/** * Combine the transaction id and the log id to an operation id. * * @param transactionId the transaction id * @param logId the log id * @return the operation id */ static long getOperationId(int transactionId, long logId) { DataUtils.checkArgument(transactionId >= 0 && transactionId < (1 << 24), "Transaction id out of range: {0}", transactionId); DataUtils.checkArgument(logId >= 0 && logId < (1L << 40), "Transaction log id out of range: {0}", logId); return ((long) transactionId << 40) | logId; }
/** * Try to update the value for the given key. * <p> * This will fail if the row is locked by another transaction (that * means, if another open transaction changed the row). * * @param key the key * @param value the new value * @return whether the entry could be updated */ public boolean tryPut(K key, V value) { DataUtils.checkArgument(value != null, "The value may not be null"); return trySet(key, value, false); }
/** * Update the value for the given key. * <p> * If the row is locked, this method will retry until the row could be * updated or until a lock timeout. * * @param key the key * @param value the new value (not null) * @return the old value * @throws IllegalStateException if a lock timeout occurs */ public V put(K key, V value) { DataUtils.checkArgument(value != null, "The value may not be null"); return set(key, value); }
/** * Set the maximum memory this cache should use. This will not * immediately cause entries to get removed however; it will only change * the limit. To resize the internal array, call the clear method. * * @param maxMemory the maximum size (1 or larger) in bytes */ public void setMaxMemory(long maxMemory) { DataUtils.checkArgument( maxMemory > 0, "Max memory must be larger than 0, is {0}", maxMemory); this.maxMemory = maxMemory; if (segments != null) { long max = 1 + maxMemory / segments.length; for (Segment<V> s : segments) { s.setMaxMemory(max); } } }
/** * Create a new cache with the given memory size. * * @param config the configuration */ @SuppressWarnings("unchecked") public CacheLongKeyLIRS(Config config) { setMaxMemory(config.maxMemory); this.nonResidentQueueSize = config.nonResidentQueueSize; DataUtils.checkArgument( Integer.bitCount(config.segmentCount) == 1, "The segment count must be a power of 2, is {0}", config.segmentCount); this.segmentCount = config.segmentCount; this.segmentMask = segmentCount - 1; this.stackMoveDistance = config.stackMoveDistance; segments = new Segment[segmentCount]; clear(); // use the high bits for the segment this.segmentShift = 32 - Integer.bitCount(segmentMask); }
/** * Update the value for the given key, without adding an undo log entry. * * @param key the key * @param value the value * @return the old value */ @SuppressWarnings("unchecked") public V putCommitted(K key, V value) { DataUtils.checkArgument(value != null, "The value may not be null"); VersionedValue newValue = new VersionedValue(0L, value); VersionedValue oldValue = map.put(key, newValue); return (V) (oldValue == null ? null : oldValue.value); }
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; }
private Set<Integer> collectReferencedChunks() { long testVersion = lastChunk.version; DataUtils.checkArgument(testVersion > 0, "Collect references on version 0"); long readCount = getFileStore().readCount.get(); Set<Integer> referenced = new HashSet<>(); for (Cursor<String, String> c = meta.cursor("root."); c.hasNext();) { String key = c.next(); if (!key.startsWith("root.")) { break; } long pos = DataUtils.parseHexLong(c.getValue()); if (pos == 0) { continue; } int mapId = DataUtils.parseHexInt(key.substring("root.".length())); collectReferencedChunks(referenced, mapId, pos, 0); } long pos = lastChunk.metaRootPos; collectReferencedChunks(referenced, 0, pos, 0); readCount = fileStore.readCount.get() - readCount; return referenced; }
/** * 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); }
/** * Add or replace a key-value pair. * * @param key the key (may not be null) * @param value the value (may not be null) * @return the old value if the key existed, or null otherwise */ @Override @SuppressWarnings("unchecked") public synchronized V put(K key, V value) { DataUtils.checkArgument(value != null, "The value may not be null"); beforeWrite(); long v = writeVersion; Page p = root.copy(v); p = splitRootIfNeeded(p, v); Object result = put(p, v, key, value); newRoot(p); return (V) result; }
return; DataUtils.checkArgument( isKnownVersion(version), "Unknown version {0}", version);
/** * 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); }
"the method on the writable map"); DataUtils.checkArgument(version >= createVersion, "Unknown version {0}; this map was created in version is {1}", version, createVersion);
public SpatialDataType(int dimensions) { // Because of how we are storing the // min-max-flag in the read/write method // the number of dimensions must be < 32. DataUtils.checkArgument( dimensions >= 1 && dimensions < 32, "Dimensions must be between 1 and 31, is {0}", dimensions); this.dimensions = dimensions; }
public SpatialDataType(int dimensions) { // Because of how we are storing the // min-max-flag in the read/write method // the number of dimensions must be < 32. DataUtils.checkArgument( dimensions >= 1 && dimensions < 32, "Dimensions must be between 1 and 31, is {0}", dimensions); this.dimensions = dimensions; }
public SpatialDataType(int dimensions) { // Because of how we are storing the // min-max-flag in the read/write method // the number of dimensions must be < 32. DataUtils.checkArgument( dimensions >= 1 && dimensions < 32, "Dimensions must be between 1 and 31, is {0}", dimensions); this.dimensions = dimensions; }
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; }
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; }
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; }