Search in sources :

Example 6 with ReadOnlyStorageEngine

use of voldemort.store.readonly.ReadOnlyStorageEngine in project voldemort by voldemort.

the class AdminServiceRequestHandler method handleGetROStorageFileList.

public VAdminProto.GetROStorageFileListResponse handleGetROStorageFileList(VAdminProto.GetROStorageFileListRequest request) {
    String storeName = request.getStoreName();
    VAdminProto.GetROStorageFileListResponse.Builder response = VAdminProto.GetROStorageFileListResponse.newBuilder();
    try {
        ReadOnlyStorageEngine store = getReadOnlyStorageEngine(metadataStore, storeRepository, storeName);
        ChunkedFileSet chunkedFileSet = store.getChunkedFileSet();
        response.addAllFileName(chunkedFileSet.getFileNames());
        response.addAllIndexFileSize(chunkedFileSet.getIndexFileSizes());
        response.addAllDataFileSize(chunkedFileSet.getDataFileSizes());
    } catch (VoldemortException e) {
        response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
        logger.error("handleGetROStorageFileList failed for request(" + request.toString() + ")", e);
    }
    return response.build();
}
Also used : ReadOnlyStorageEngine(voldemort.store.readonly.ReadOnlyStorageEngine) VoldemortException(voldemort.VoldemortException) ChunkedFileSet(voldemort.store.readonly.chunk.ChunkedFileSet)

Example 7 with ReadOnlyStorageEngine

use of voldemort.store.readonly.ReadOnlyStorageEngine in project voldemort by voldemort.

the class Rebalancer method swapROStores.

/**
     * Goes through all the RO Stores in the plan and swaps it
     * 
     * @param swappedStoreNames Names of stores already swapped
     * @param useSwappedStoreNames Swap only the previously swapped stores (
     *        Happens during error )
     */
private void swapROStores(List<String> swappedStoreNames, boolean useSwappedStoreNames) {
    try {
        for (StoreDefinition storeDef : metadataStore.getStoreDefList()) {
            // Only pick up the RO stores
            if (storeDef.getType().compareTo(ReadOnlyStorageConfiguration.TYPE_NAME) == 0) {
                if (useSwappedStoreNames && !swappedStoreNames.contains(storeDef.getName())) {
                    continue;
                }
                ReadOnlyStorageEngine engine = (ReadOnlyStorageEngine) storeRepository.getStorageEngine(storeDef.getName());
                if (engine == null) {
                    throw new VoldemortException("Could not find storage engine for " + storeDef.getName() + " to swap ");
                }
                logger.info("Swapping RO store " + storeDef.getName());
                // Time to swap this store - Could have used admin client,
                // but why incur the overhead?
                engine.swapFiles(engine.getCurrentDirPath());
                // Add to list of stores already swapped
                if (!useSwappedStoreNames)
                    swappedStoreNames.add(storeDef.getName());
            }
        }
    } catch (Exception e) {
        logger.error("Error while swapping RO store");
        throw new VoldemortException(e);
    }
}
Also used : StoreDefinition(voldemort.store.StoreDefinition) ReadOnlyStorageEngine(voldemort.store.readonly.ReadOnlyStorageEngine) VoldemortException(voldemort.VoldemortException) VoldemortException(voldemort.VoldemortException)

Example 8 with ReadOnlyStorageEngine

use of voldemort.store.readonly.ReadOnlyStorageEngine in project voldemort by voldemort.

the class ReadOnlyStoreManagementServlet method doSwap.

private void doSwap(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
    String dir = getRequired(req, "dir");
    String storeName = getRequired(req, "store");
    if (metadataStore != null && !metadataStore.getServerStateUnlocked().equals(MetadataStore.VoldemortState.NORMAL_SERVER) && !metadataStore.getServerStateUnlocked().equals(MetadataStore.VoldemortState.OFFLINE_SERVER)) {
        throw new ServletException("Voldemort server is neither in normal state nor in offline state");
    }
    ReadOnlyStorageEngine store = this.getStore(storeName);
    if (store == null)
        throw new ServletException("'" + storeName + "' is not a registered read-only store.");
    if (!Utils.isReadableDir(dir))
        throw new ServletException("Store directory '" + dir + "' is not a readable directory.");
    // Retrieve the current directory before swapping it
    String currentDirPath = store.getCurrentDirPath();
    // Swap with the new directory
    store.swapFiles(dir);
    // Send back the previous directory
    resp.getWriter().write(currentDirPath);
}
Also used : ServletException(javax.servlet.ServletException) ReadOnlyStorageEngine(voldemort.store.readonly.ReadOnlyStorageEngine)

Example 9 with ReadOnlyStorageEngine

use of voldemort.store.readonly.ReadOnlyStorageEngine in project voldemort by voldemort.

the class ReadOnlyStoreManagementServlet method doRollback.

private void doRollback(HttpServletRequest req) throws ServletException {
    String storeName = getRequired(req, "store");
    long pushVersion = Long.parseLong(getRequired(req, "pushVersion"));
    ReadOnlyStorageEngine store = getStore(storeName);
    if (store == null)
        throw new ServletException("'" + storeName + "' is not a registered read-only store.");
    try {
        File rollbackVersionDir = new File(store.getStoreDirPath(), "version-" + pushVersion);
        store.rollback(rollbackVersionDir);
    } catch (Exception e) {
        throw new ServletException("Exception in rollback = " + e.getMessage());
    }
}
Also used : ServletException(javax.servlet.ServletException) ReadOnlyStorageEngine(voldemort.store.readonly.ReadOnlyStorageEngine) File(java.io.File) ServletException(javax.servlet.ServletException) VoldemortException(voldemort.VoldemortException) IOException(java.io.IOException)

Example 10 with ReadOnlyStorageEngine

use of voldemort.store.readonly.ReadOnlyStorageEngine in project voldemort by voldemort.

the class ReadOnlyStoreManagementServlet method doFetch.

private void doFetch(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
    String fetchUrl = getRequired(req, "dir");
    String storeName = getRequired(req, "store");
    String pushVersionString = getOptional(req, "pushVersion");
    ReadOnlyStorageEngine store = this.getStore(storeName);
    if (store == null)
        throw new ServletException("'" + storeName + "' is not a registered read-only store.");
    long pushVersion;
    if (pushVersionString == null) {
        // Find the max version
        long maxVersion;
        File[] storeDirList = ReadOnlyUtils.getVersionDirs(new File(store.getStoreDirPath()));
        if (storeDirList == null || storeDirList.length == 0) {
            throw new ServletException("Push version required since no version folders exist");
        } else {
            maxVersion = ReadOnlyUtils.getVersionId(ReadOnlyUtils.findKthVersionedDir(storeDirList, storeDirList.length - 1, storeDirList.length - 1)[0]);
        }
        pushVersion = maxVersion + 1;
    } else {
        pushVersion = Long.parseLong(pushVersionString);
        if (pushVersion <= store.getCurrentVersionId())
            throw new ServletException("Version of push specified (" + pushVersion + ") should be greater than current version " + store.getCurrentVersionId());
    }
    // fetch the files if necessary
    File fetchDir = null;
    if (fileFetcher == null) {
        logger.warn("File fetcher class has not instantiated correctly. Assuming local file");
        if (!Utils.isReadableDir(fetchUrl)) {
            throw new ServletException("Fetch url " + fetchUrl + " is not readable");
        }
        fetchDir = new File(store.getStoreDirPath(), "version-" + Long.toString(pushVersion));
        if (fetchDir.exists())
            throw new ServletException("Version directory " + fetchDir.getAbsolutePath() + " already exists");
        Utils.move(new File(fetchUrl), fetchDir);
    } else {
        logger.info("Executing fetch of " + fetchUrl);
        try {
            fetchDir = fileFetcher.fetch(fetchUrl, store.getStoreDirPath() + File.separator + "version-" + Long.toString(pushVersion));
            if (fetchDir == null) {
                throw new ServletException("File fetcher failed for " + fetchUrl + " and store name = " + storeName + " due to incorrect input path/checksum error");
            } else {
                logger.info("Fetch complete.");
            }
        } catch (Exception e) {
            throw new ServletException("Exception in Fetcher = " + e.getMessage());
        }
    }
    resp.getWriter().write(fetchDir.getAbsolutePath());
}
Also used : ServletException(javax.servlet.ServletException) ReadOnlyStorageEngine(voldemort.store.readonly.ReadOnlyStorageEngine) File(java.io.File) ServletException(javax.servlet.ServletException) VoldemortException(voldemort.VoldemortException) IOException(java.io.IOException)

Aggregations

ReadOnlyStorageEngine (voldemort.store.readonly.ReadOnlyStorageEngine)21 VoldemortException (voldemort.VoldemortException)15 File (java.io.File)12 StoreDefinition (voldemort.store.StoreDefinition)6 ByteArray (voldemort.utils.ByteArray)5 IOException (java.io.IOException)4 ServletException (javax.servlet.ServletException)4 Cluster (voldemort.cluster.Cluster)4 Pair (voldemort.utils.Pair)4 Versioned (voldemort.versioning.Versioned)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 VAdminProto (voldemort.client.protocol.pb.VAdminProto)3 RoutingStrategyFactory (voldemort.routing.RoutingStrategyFactory)3 SerializerDefinition (voldemort.serialization.SerializerDefinition)3 StoreDefinitionBuilder (voldemort.store.StoreDefinitionBuilder)3 Set (java.util.Set)2 Path (org.apache.hadoop.fs.Path)2 JobConf (org.apache.hadoop.mapred.JobConf)2 Test (org.junit.Test)2