use of voldemort.versioning.Versioned in project voldemort by voldemort.
the class RetentionEnforcingStore method getAll.
@Override
public Map<ByteArray, List<Versioned<byte[]>>> getAll(Iterable<ByteArray> keys, Map<ByteArray, byte[]> transforms) throws VoldemortException {
StoreUtils.assertValidKeys(keys);
Map<ByteArray, List<Versioned<byte[]>>> results = getInnerStore().getAll(keys, transforms);
if (!storeDef.hasRetentionPeriod())
return results;
for (ByteArray key : results.keySet()) {
List<Versioned<byte[]>> filteredVals = filterExpiredEntries(key, results.get(key));
// filtered
if (!filteredVals.isEmpty())
results.put(key, filteredVals);
else
results.remove(key);
}
return results;
}
use of voldemort.versioning.Versioned in project voldemort by voldemort.
the class MetadataStore method convertObjectToString.
/**
* Converts Object to byte[] depending on the key
* <p>
* StoreRepository takes only StorageEngine<ByteArray,byte[]> and for
* persistence on disk we need to convert them to String.<br>
*
* @param key
* @param value
* @return
*/
@SuppressWarnings("unchecked")
private Versioned<String> convertObjectToString(String key, Versioned<Object> value) {
String valueStr = "";
if (CLUSTER_KEY.equals(key)) {
valueStr = clusterMapper.writeCluster((Cluster) value.getValue());
} else if (STORES_KEY.equals(key)) {
valueStr = storeMapper.writeStoreList((List<StoreDefinition>) value.getValue());
} else if (REBALANCING_STEAL_INFO.equals(key)) {
RebalancerState rebalancerState = (RebalancerState) value.getValue();
valueStr = rebalancerState.toJsonString();
} else if (SERVER_STATE_KEY.equals(key) || NODE_ID_KEY.equals(key) || SLOP_STREAMING_ENABLED_KEY.equals(key) || PARTITION_STREAMING_ENABLED_KEY.equals(key) || READONLY_FETCH_ENABLED_KEY.equals(key) || QUOTA_ENFORCEMENT_ENABLED_KEY.equals(key)) {
valueStr = value.getValue().toString();
} else if (REBALANCING_SOURCE_CLUSTER_XML.equals(key)) {
if (value.getValue() != null) {
valueStr = clusterMapper.writeCluster((Cluster) value.getValue());
}
} else if (REBALANCING_SOURCE_STORES_XML.equals(key)) {
if (value.getValue() != null) {
valueStr = storeMapper.writeStoreList((List<StoreDefinition>) value.getValue());
}
} else if (this.storeNames.contains(key)) {
valueStr = "<stores>";
if (value.getValue() != null) {
valueStr += value.getValue();
}
valueStr += "</stores>";
} else {
throw new VoldemortException("Unhandled key:'" + key + "' for Object to String serialization.");
}
return new Versioned<String>(valueStr, value.getVersion());
}
use of voldemort.versioning.Versioned in project voldemort by voldemort.
the class MetadataStore method updateStoreDefinitions.
/**
* Function to update store definitions. Unlike the put method, this
* function does not delete any existing state. It only updates the state of
* the stores specified in the given stores.xml
*
* @param valueBytes specifies the bytes of the stores.xml containing
* updates for the specified stores
*/
@SuppressWarnings("unchecked")
public void updateStoreDefinitions(Versioned<byte[]> valueBytes) {
// acquire write lock
writeLock.lock();
try {
Versioned<String> value = new Versioned<String>(ByteUtils.getString(valueBytes.getValue(), "UTF-8"), valueBytes.getVersion());
Versioned<Object> valueObject = convertStringToObject(STORES_KEY, value);
StoreDefinitionsMapper mapper = new StoreDefinitionsMapper();
List<StoreDefinition> storeDefinitions = (List<StoreDefinition>) valueObject.getValue();
// Check for backwards compatibility
StoreDefinitionUtils.validateSchemasAsNeeded(storeDefinitions);
StoreDefinitionUtils.validateNewStoreDefsAreNonBreaking(getStoreDefList(), storeDefinitions);
// Go through each store definition and do a corresponding put
for (StoreDefinition storeDef : storeDefinitions) {
if (!this.storeNames.contains(storeDef.getName())) {
throw new VoldemortException("Cannot update a store which does not exist !");
}
String storeDefStr = mapper.writeStore(storeDef);
Versioned<String> versionedValueStr = new Versioned<String>(storeDefStr, value.getVersion());
this.storeDefinitionsStorageEngine.put(storeDef.getName(), versionedValueStr, "");
// Update the metadata cache
this.metadataCache.put(storeDef.getName(), new Versioned<Object>(storeDefStr, value.getVersion()));
}
// Re-initialize the store definitions
initStoreDefinitions(value.getVersion());
// Update routing strategies
// TODO: Make this more fine grained.. i.e only update listeners for
// a specific store.
updateRoutingStrategies(getCluster(), getStoreDefList());
} finally {
writeLock.unlock();
}
}
use of voldemort.versioning.Versioned in project voldemort by voldemort.
the class MysqlStorageEngine method getAll.
@Override
public Map<ByteArray, List<Versioned<byte[]>>> getAll(Iterable<ByteArray> keys, Map<ByteArray, byte[]> transforms) throws VoldemortException {
StoreUtils.assertValidKeys(keys);
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
String select = "select version_, value_ from " + getName() + " where key_ = ?";
try {
conn = datasource.getConnection();
stmt = conn.prepareStatement(select);
Map<ByteArray, List<Versioned<byte[]>>> result = StoreUtils.newEmptyHashMap(keys);
for (ByteArray key : keys) {
stmt.setBytes(1, key.get());
rs = stmt.executeQuery();
List<Versioned<byte[]>> found = Lists.newArrayList();
while (rs.next()) {
byte[] version = rs.getBytes("version_");
byte[] value = rs.getBytes("value_");
found.add(new Versioned<byte[]>(value, new VectorClock(version)));
}
if (found.size() > 0)
result.put(key, found);
}
return result;
} catch (SQLException e) {
throw new PersistenceFailureException("Fix me!", e);
} finally {
tryClose(rs);
tryClose(stmt);
tryClose(conn);
}
}
use of voldemort.versioning.Versioned in project voldemort by voldemort.
the class QuotaUtils method setQuota.
public static void setQuota(String storeName, QuotaType type, StoreRepository repository, Set<Integer> nodeIds, long lquota) {
FileBackedCachingStorageEngine quotaStore = getQuotaStore(repository);
String quotaKey = makeQuotaKey(storeName, QuotaType.STORAGE_SPACE);
ByteArray keyArray = convertToByteArray(quotaKey);
List<Versioned<byte[]>> existingValue = quotaStore.get(keyArray, null);
String quotaValue = Long.toString(lquota);
ByteArray valueArray = convertToByteArray(quotaValue);
VectorClock newClock = VectorClockUtils.makeClockWithCurrentTime(nodeIds);
Versioned<byte[]> newValue = new Versioned<byte[]>(valueArray.get(), newClock);
quotaStore.put(keyArray, newValue, null);
}
Aggregations