/** * 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); }
@Override public boolean isEmpty() { return queueMap.isEmpty(); }
/** * Add a key-value pair if it does not yet exist. * * @param key the key (may not be null) * @param value the new value * @return the old value if the key existed, or null otherwise */ @Override public synchronized V putIfAbsent(K key, V value) { V old = get(key); if (old == null) { put(key, value); } return old; }
/** * Remove a key-value pair if the value matches the stored one. * * @param key the key (may not be null) * @param value the expected value * @return true if the item was removed */ @Override public synchronized boolean remove(Object key, Object value) { V old = get(key); if (areValuesEqual(old, value)) { remove(key); return true; } return false; }
/** * Replace a value for an existing key, if the value matches. * * @param key the key (may not be null) * @param oldValue the expected value * @param newValue the new value * @return true if the value was replaced */ @Override public synchronized boolean replace(K key, V oldValue, V newValue) { V old = get(key); if (areValuesEqual(old, oldValue)) { put(key, newValue); return true; } return false; }
m.close(); meta.clear(); chunks.clear(); if (fileStore != null) { "Unknown version {0}", version); for (MVMap<?, ?> m : maps.values()) { m.rollbackTo(version); meta.rollbackTo(version); metaChanged = false; boolean loadFromFile = false; int id = m.getId(); if (m.getCreateVersion() >= version) { m.close(); maps.remove(id); } else { if (loadFromFile) { m.setRootPos(getRootPos(meta, id), -1); meta.put(Chunk.getMetaKey(c.id), c.asString());
/** * 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); }
transaction.store.rwLock.readLock().lock(); try { long sizeRaw = map.sizeAsLong(); MVMap<Long, Object[]> undo = transaction.store.undoLog; long undoLogSize; synchronized (undo) { undoLogSize = undo.sizeAsLong(); Cursor<K, VersionedValue> cursor = map.cursor(null); while (cursor.hasNext()) { K key = cursor.next(); VersionedValue data = map.get(key); data = getValue(key, readLogId, data); if (data != null && data.value != null) { long size = map.sizeAsLong(); MVMap<Object, Integer> temp = transaction.store .createTempMap(); try { for (Entry<Long, Object[]> e : undo.entrySet()) { Object[] op = e.getValue(); int m = (Integer) op[0]; K key = (K) op[1]; if (get(key) == null) { Integer old = temp.put(key, 1);
LOG.debug("Active count: " + mapActive.size()); LOG.debug("Cache count: " + mapCached.size()); LOG.debug("Processed valid count: " + mapProcessedValid.size()); LOG.debug("Processed invalid count: " + mapProcessedInvalid.size()); LOG.debug(path + " Putting active URLs back in the queue..."); for (String key : mapActive.keySet()) { mapQueued.put(key, mapActive.remove(key)); mapCached.clear(); mapActive.clear(); mapQueued.clear(); mapProcessedInvalid.clear(); for (String key : mapProcessedValid.keySet()) { ICrawlData processed = mapProcessedValid.remove(key); if (processed.getState().isGoodState()) { mapCached.put(key, processed);
H2PersistentQueue(MVStore store, String queueName) { if (queueName == null || queueName.isEmpty()) { throw new IllegalArgumentException("queueName parameter can't be empty or null"); } this.queueMap = store.openMap("queue_" + queueName); this.metadataMap = store.openMap("queue_" + queueName + "_meta"); //setup head index long headIdx = 0L; if (this.metadataMap.containsKey("head")) { headIdx = this.metadataMap.get("head"); } else { this.metadataMap.put("head", headIdx); } this.head = new AtomicLong(headIdx); //setup tail index long tailIdx = 0L; if (this.metadataMap.containsKey("tail")) { tailIdx = this.metadataMap.get("tail"); } else { this.metadataMap.put("tail", tailIdx); } this.tail = new AtomicLong(tailIdx); }
return; if (dataMap.isEmpty()) { return; for (Entry<Long, Object[]> e : lobMap.entrySet()) { long lobId = e.getKey(); Object[] v = e.getValue(); Long last = dataMap.lastKey(); if (last == null || last <= lastUsedKey) { break; trace("gc " + last); dataMap.remove(last); Long last = dataMap.lastKey(); if (last != null) { streamStore.setNextKey(last + 1);
try { ArrayList<Transaction> list = New.arrayList(); Long key = undoLog.firstKey(); while (key != null) { int transactionId = getTransactionId(key); key = undoLog.lowerKey(getOperationId(transactionId + 1, 0)); long logId = getLogId(key) + 1; Object[] data = preparedTransactions.get(transactionId); int status; String name; if (data == null) { if (undoLog.containsKey(getOperationId(transactionId, 0))) { status = Transaction.STATUS_OPEN; } else { name, logId); list.add(t); key = undoLog.ceilingKey(getOperationId(transactionId + 1, 0));
/** * Remove a key-value pair, if the key exists. * * @param key the key (may not be null) * @return the old value if the key existed, or null otherwise */ @Override @SuppressWarnings("unchecked") public V remove(Object key) { beforeWrite(); V result = get(key); if (result == null) { return null; } long v = writeVersion; synchronized (this) { Page p = root.copy(v); result = (V) remove(p, v, key); if (!p.isLeaf() && p.getTotalCount() == 0) { p.removePage(); p = Page.createEmpty(this, p.getVersion()); } newRoot(p); } return result; }
/** * 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; }
"PRIMARY KEY(LOB_ID, SEQ));"); boolean hasErrors = false; for (Entry<Long, Object[]> e : lobMap.entrySet()) { long lobId = e.getKey(); Object[] value = e.getValue(); writer.println("-- lobMap.size: " + lobMap.sizeAsLong()); writer.println("-- lobData.size: " + lobData.sizeAsLong()); for (Long k : lobMap.keyList()) { Object[] value = lobMap.get(k); byte[] streamStoreId = (byte[]) value[0]; writer.println("-- " + k + " " + StreamStore.toString(streamStoreId)); for (Long k : lobData.keyList()) { writer.println("-- " + k + " len " + lobData.get(k).length);
for (Iterator<String> it = oldMeta.keyIterator("chunk."); it.hasNext();) { String chunkKey = it.next(); break; if (!meta.containsKey(chunkKey)) { String s = oldMeta.get(chunkKey); Chunk c2 = Chunk.fromString(s); Chunk test = readChunkHeaderAndFooter(c2.block);
/** * Get one of the previous or next keys. There might be no value * available for the returned key. * * @param key the key (may not be null) * @param offset how many keys to skip (-1 for previous, 1 for next) * @return the key */ public K relativeKey(K key, long offset) { K k = offset > 0 ? map.ceilingKey(key) : map.floorKey(key); if (k == null) { return k; } long index = map.getKeyIndex(k); return map.getKey(index + offset); }
/** * End this transaction * * @param t the transaction * @param oldStatus status of this transaction */ synchronized void endTransaction(Transaction t, int oldStatus) { if (oldStatus == Transaction.STATUS_PREPARED) { preparedTransactions.remove(t.getId()); } t.setStatus(Transaction.STATUS_CLOSED); openTransactions.clear(t.transactionId); if (oldStatus == Transaction.STATUS_PREPARED || store.getAutoCommitDelay() == 0) { store.commit(); return; } // to avoid having to store the transaction log, // if there is no open transaction, // and if there have been many changes, store them now if (undoLog.isEmpty()) { int unsaved = store.getUnsavedMemory(); int max = store.getAutoCommitMemory(); // save at 3/4 capacity if (unsaved * 4 > max * 3) { store.commit(); } } }