Search in sources :

Example 1 with ConfigurationStorageEngine

use of voldemort.store.configuration.ConfigurationStorageEngine in project voldemort by voldemort.

the class MetadataStore method readFromDirectory.

public static MetadataStore readFromDirectory(File dir) {
    if (!Utils.isReadableDir(dir))
        throw new IllegalArgumentException("Metadata directory " + dir.getAbsolutePath() + " does not exist or can not be read.");
    String storeDefDirPath = dir.getAbsolutePath() + File.separator + MetadataStore.STORE_DEFINITIONS_STORE_NAME;
    // If config directory does not contain STORES sub directory, then
    // create one by parsing the stores.xml file
    List<String> configurationFiles = Arrays.asList(dir.list());
    if (configurationFiles == null)
        throw new IllegalArgumentException("No configuration found in " + dir.getAbsolutePath() + ".");
    if (!configurationFiles.contains(STORE_DEFINITIONS_STORE_NAME)) {
        // parse stores.xml and create STORES sub-dir
        StoreDefinitionsMapper mapper = new StoreDefinitionsMapper();
        List<StoreDefinition> storeDefinitions = null;
        try {
            storeDefinitions = mapper.readStoreList(new File(dir.getAbsolutePath() + File.separator + STORES_KEY));
        } catch (IOException e) {
            throw new VoldemortException("Cannot parse the store definitions from " + STORES_KEY + " file ", e);
        }
        if (storeDefinitions == null) {
            throw new VoldemortException("Neither STORES nor stores.xml exist in the config directory");
        }
        // Create the STORES sub directory
        File storeDefinitionsDir = new File(storeDefDirPath);
        if (!storeDefinitionsDir.mkdir()) {
            throw new VoldemortException("Unable to create " + STORE_DEFINITIONS_STORE_NAME + " sub directory");
        }
        for (StoreDefinition storeDef : storeDefinitions) {
            try {
                FileUtils.writeStringToFile(new File(storeDefDirPath + File.separator + storeDef.getName()), mapper.writeStore(storeDef));
            } catch (IOException e) {
                throw new VoldemortException("Cannot write store definition to file: " + storeDef.getName(), e);
            }
        }
    }
    // Create a STORES configuration engine for STORES sub-directory
    StorageEngine<String, String, String> storesEngine = new ConfigurationStorageEngine(MetadataStore.STORE_DEFINITIONS_STORE_NAME, storeDefDirPath);
    Store<String, String, String> innerStore = new ConfigurationStorageEngine(MetadataStore.METADATA_STORE_NAME, dir.getAbsolutePath());
    MetadataStore store = new MetadataStore(innerStore, storesEngine);
    ServerState state = new ServerState(store);
    JmxUtils.registerMbean(state.getClass().getCanonicalName(), state);
    return store;
}
Also used : ServerState(voldemort.server.ServerState) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) ConfigurationStorageEngine(voldemort.store.configuration.ConfigurationStorageEngine) IOException(java.io.IOException) VoldemortException(voldemort.VoldemortException) StoreDefinition(voldemort.store.StoreDefinition) File(java.io.File)

Example 2 with ConfigurationStorageEngine

use of voldemort.store.configuration.ConfigurationStorageEngine in project voldemort by voldemort.

the class VoldemortServer method getTestMetadataStore.

private static MetadataStore getTestMetadataStore(VoldemortConfig voldemortConfig, Cluster cluster) {
    ConfigurationStorageEngine metadataInnerEngine = new ConfigurationStorageEngine("metadata-config-store", voldemortConfig.getMetadataDirectory());
    List<Versioned<String>> clusterXmlValue = metadataInnerEngine.get(MetadataStore.CLUSTER_KEY, null);
    VectorClock version = null;
    if (clusterXmlValue.size() <= 0) {
        version = new VectorClock();
    } else {
        version = (VectorClock) clusterXmlValue.get(0).getVersion();
    }
    int nodeId = getNodeId(voldemortConfig, cluster);
    version.incrementVersion(nodeId, System.currentTimeMillis());
    metadataInnerEngine.put(MetadataStore.CLUSTER_KEY, new Versioned<String>(new ClusterMapper().writeCluster(cluster), version), null);
    return MetadataStore.createInMemoryMetadataStore(metadataInnerEngine, nodeId);
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) ConfigurationStorageEngine(voldemort.store.configuration.ConfigurationStorageEngine) ClusterMapper(voldemort.xml.ClusterMapper)

Aggregations

ConfigurationStorageEngine (voldemort.store.configuration.ConfigurationStorageEngine)2 File (java.io.File)1 IOException (java.io.IOException)1 VoldemortException (voldemort.VoldemortException)1 ServerState (voldemort.server.ServerState)1 StoreDefinition (voldemort.store.StoreDefinition)1 VectorClock (voldemort.versioning.VectorClock)1 Versioned (voldemort.versioning.Versioned)1 ClusterMapper (voldemort.xml.ClusterMapper)1 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)1