Search in sources :

Example 16 with Versioned

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;
}
Also used : Versioned(voldemort.versioning.Versioned) ByteArray(voldemort.utils.ByteArray) List(java.util.List)

Example 17 with Versioned

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());
}
Also used : Versioned(voldemort.versioning.Versioned) StoreDefinition(voldemort.store.StoreDefinition) Cluster(voldemort.cluster.Cluster) RebalancerState(voldemort.server.rebalance.RebalancerState) VoldemortException(voldemort.VoldemortException)

Example 18 with Versioned

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();
    }
}
Also used : Versioned(voldemort.versioning.Versioned) StoreDefinition(voldemort.store.StoreDefinition) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) List(java.util.List) ArrayList(java.util.ArrayList) VoldemortException(voldemort.VoldemortException)

Example 19 with Versioned

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);
    }
}
Also used : Versioned(voldemort.versioning.Versioned) SQLException(java.sql.SQLException) VectorClock(voldemort.versioning.VectorClock) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) PersistenceFailureException(voldemort.store.PersistenceFailureException) ResultSet(java.sql.ResultSet) ByteArray(voldemort.utils.ByteArray) List(java.util.List)

Example 20 with Versioned

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);
}
Also used : FileBackedCachingStorageEngine(voldemort.store.configuration.FileBackedCachingStorageEngine) Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) ByteArray(voldemort.utils.ByteArray)

Aggregations

Versioned (voldemort.versioning.Versioned)214 ByteArray (voldemort.utils.ByteArray)130 Test (org.junit.Test)88 VectorClock (voldemort.versioning.VectorClock)73 ArrayList (java.util.ArrayList)56 VoldemortException (voldemort.VoldemortException)48 List (java.util.List)36 StoreDefinition (voldemort.store.StoreDefinition)29 HashMap (java.util.HashMap)28 IOException (java.io.IOException)27 Node (voldemort.cluster.Node)27 Pair (voldemort.utils.Pair)25 Slop (voldemort.store.slop.Slop)22 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)22 Map (java.util.Map)21 Cluster (voldemort.cluster.Cluster)17 AbstractByteArrayStoreTest (voldemort.store.AbstractByteArrayStoreTest)15 InvalidMetadataException (voldemort.store.InvalidMetadataException)13 PersistenceFailureException (voldemort.store.PersistenceFailureException)13 Version (voldemort.versioning.Version)13