Search in sources :

Example 16 with ReadOnlyStorageEngine

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

the class AdminServiceRequestHandler method handleFetchROStore.

public VAdminProto.AsyncOperationStatusResponse handleFetchROStore(VAdminProto.FetchStoreRequest request) {
    final String fetchUrl = request.getStoreDir();
    final String storeName = request.getStoreName();
    int requestId = asyncService.getUniqueRequestId();
    VAdminProto.AsyncOperationStatusResponse.Builder response = VAdminProto.AsyncOperationStatusResponse.newBuilder().setRequestId(requestId).setComplete(false).setDescription("Fetch store").setStatus("started");
    try {
        if (!metadataStore.getReadOnlyFetchEnabledUnlocked()) {
            throw new ReadOnlyFetchDisabledException("Pushes to this node have been disabled." + " Please reach out to the cluster admin for assistance.");
        }
        final ReadOnlyStorageEngine store = getReadOnlyStorageEngine(metadataStore, storeRepository, storeName);
        final long pushVersion;
        if (request.hasPushVersion()) {
            pushVersion = request.getPushVersion();
            if (pushVersion <= store.getCurrentVersionId())
                throw new VoldemortException("Version of push specified (" + pushVersion + ") should be greater than current version " + store.getCurrentVersionId() + " for store " + storeName + " on node " + metadataStore.getNodeId());
        } else {
            // Find the max version
            long maxVersion;
            File[] storeDirList = ReadOnlyUtils.getVersionDirs(new File(store.getStoreDirPath()));
            if (storeDirList == null || storeDirList.length == 0) {
                throw new VoldemortException("Push version required since no version folders exist for store " + storeName + " on node " + metadataStore.getNodeId());
            } else {
                maxVersion = ReadOnlyUtils.getVersionId(ReadOnlyUtils.findKthVersionedDir(storeDirList, storeDirList.length - 1, storeDirList.length - 1)[0]);
            }
            pushVersion = maxVersion + 1;
            logger.warn("Push Version is not specified, this might create issues during rebalance/restore. Store" + storeName + " Generated version " + pushVersion);
        }
        Long diskQuotaSizeInKB = QuotaUtils.getQuota(storeName, QuotaType.STORAGE_SPACE, storeRepository);
        ReadOnlyStoreFetchOperation operation = new ReadOnlyStoreFetchOperation(requestId, metadataStore, store, fileFetcher, storeName, fetchUrl, pushVersion, diskQuotaSizeInKB);
        AdminServiceRequestHandler.storeLock.lock();
        try {
            boolean complete;
            int previousRequestId = store.getFetchingRequest();
            if (previousRequestId != ReadOnlyStorageEngine.NO_FETCH_IN_PROGRESS) {
                try {
                    complete = asyncService.isComplete(store.getFetchingRequest(), false);
                } catch (VoldemortException e) {
                    complete = true;
                }
                if (!complete)
                    throw new VoldemortException("The store: " + storeName + " is currently blocked since it is fetching data " + "(existing operation request ID: " + previousRequestId + ")");
            }
            store.setFetchingRequest(requestId);
            asyncService.submitOperation(requestId, operation);
        } finally {
            AdminServiceRequestHandler.storeLock.unlock();
        }
    } catch (VoldemortException e) {
        response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
        logger.error("handleFetchStore failed for request(" + request.toString() + ")", e);
    }
    return response.build();
}
Also used : ReadOnlyStorageEngine(voldemort.store.readonly.ReadOnlyStorageEngine) VoldemortException(voldemort.VoldemortException) File(java.io.File)

Example 17 with ReadOnlyStorageEngine

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

the class ReadOnlyStoreManagementServlet method doFailedFetch.

private void doFailedFetch(HttpServletRequest req) throws ServletException {
    String dir = getRequired(req, "dir");
    String storeName = getRequired(req, "store");
    try {
        if (!Utils.isReadableDir(dir))
            throw new ServletException("Could not read folder " + dir + " correctly to delete it");
        ReadOnlyStorageEngine store = this.getStore(storeName);
        if (store.getCurrentVersionId() == ReadOnlyUtils.getVersionId(new File(dir))) {
            logger.warn("Cannot delete " + dir + " for " + storeName + " since it is the current dir");
            return;
        }
        Utils.rm(new File(dir));
    } catch (Exception e) {
        throw new ServletException(e);
    }
}
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 18 with ReadOnlyStorageEngine

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

the class AdminServiceRequestHandler method swapStore.

/**
     * Given a read-only store name and a directory, swaps it in while returning
     * the directory path being swapped out
     *
     * @param storeName The name of the read-only store
     * @param directory The directory being swapped in
     * @return The directory path which was swapped out
     * @throws VoldemortException
     */
private String swapStore(String storeName, String directory) throws VoldemortException {
    ReadOnlyStorageEngine store = getReadOnlyStorageEngine(metadataStore, storeRepository, storeName);
    if (!Utils.isReadableDir(directory))
        throw new VoldemortException("Store directory '" + directory + "' is not a readable directory.");
    String currentDirPath = store.getCurrentDirPath();
    logger.info("Swapping RO store '" + storeName + "' to version directory '" + directory + "'");
    store.swapFiles(directory);
    logger.info("Swapping swapped RO store '" + storeName + "' to version directory '" + directory + "'");
    return currentDirPath;
}
Also used : ReadOnlyStorageEngine(voldemort.store.readonly.ReadOnlyStorageEngine) VoldemortException(voldemort.VoldemortException)

Example 19 with ReadOnlyStorageEngine

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

the class AdminServiceRequestHandler method handleGetROStorageFormat.

public VAdminProto.GetROStorageFormatResponse handleGetROStorageFormat(VAdminProto.GetROStorageFormatRequest request) {
    final List<String> storeNames = request.getStoreNameList();
    VAdminProto.GetROStorageFormatResponse.Builder response = VAdminProto.GetROStorageFormatResponse.newBuilder();
    try {
        for (String storeName : storeNames) {
            ReadOnlyStorageEngine store = getReadOnlyStorageEngine(metadataStore, storeRepository, storeName);
            VAdminProto.ROStoreVersionDirMap storeResponse = VAdminProto.ROStoreVersionDirMap.newBuilder().setStoreName(storeName).setStoreDir(store.getReadOnlyStorageFormat().getCode()).build();
            response.addRoStoreVersions(storeResponse);
        }
    } catch (VoldemortException e) {
        response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
        logger.error("handleGetROStorageFormat failed for request(" + request.toString() + ")", e);
    }
    return response.build();
}
Also used : ReadOnlyStorageEngine(voldemort.store.readonly.ReadOnlyStorageEngine) VAdminProto(voldemort.client.protocol.pb.VAdminProto) VoldemortException(voldemort.VoldemortException)

Example 20 with ReadOnlyStorageEngine

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

the class AdminServiceBasicTest method testGetROVersions.

@Test
public void testGetROVersions() {
    // Tests get current version
    Map<String, Long> storesToVersions = getAdminClient().readonlyOps.getROCurrentVersion(0, Lists.newArrayList("test-readonly-fetchfiles", "test-readonly-versions"));
    assertEquals(storesToVersions.size(), 2);
    assertEquals(storesToVersions.get("test-readonly-fetchfiles").longValue(), 0);
    assertEquals(storesToVersions.get("test-readonly-versions").longValue(), 0);
    // Tests get maximum version
    storesToVersions = getAdminClient().readonlyOps.getROMaxVersion(0, Lists.newArrayList("test-readonly-fetchfiles", "test-readonly-versions"));
    assertEquals(storesToVersions.size(), 2);
    assertEquals(storesToVersions.get("test-readonly-fetchfiles").longValue(), 0);
    assertEquals(storesToVersions.get("test-readonly-versions").longValue(), 0);
    // Tests global get maximum versions
    storesToVersions = getAdminClient().readonlyOps.getROMaxVersion(Lists.newArrayList("test-readonly-fetchfiles", "test-readonly-versions"));
    assertEquals(storesToVersions.size(), 2);
    assertEquals(storesToVersions.get("test-readonly-fetchfiles").longValue(), 0);
    assertEquals(storesToVersions.get("test-readonly-versions").longValue(), 0);
    ReadOnlyStorageEngine storeNode0 = (ReadOnlyStorageEngine) getStore(0, "test-readonly-fetchfiles");
    ReadOnlyStorageEngine storeNode1 = (ReadOnlyStorageEngine) getStore(1, "test-readonly-fetchfiles");
    Utils.mkdirs(new File(storeNode0.getStoreDirPath(), "version-10"));
    File newVersionNode1 = new File(storeNode1.getStoreDirPath(), "version-11");
    Utils.mkdirs(newVersionNode1);
    storeNode1.swapFiles(newVersionNode1.getAbsolutePath());
    // Node 0
    // Test current version
    storesToVersions = getAdminClient().readonlyOps.getROCurrentVersion(0, Lists.newArrayList("test-readonly-fetchfiles"));
    assertEquals(storesToVersions.get("test-readonly-fetchfiles").longValue(), 0);
    // Test max version
    storesToVersions = getAdminClient().readonlyOps.getROMaxVersion(0, Lists.newArrayList("test-readonly-fetchfiles"));
    assertEquals(storesToVersions.get("test-readonly-fetchfiles").longValue(), 10);
    // Node 1
    // Test current version
    storesToVersions = getAdminClient().readonlyOps.getROCurrentVersion(1, Lists.newArrayList("test-readonly-fetchfiles"));
    assertEquals(storesToVersions.get("test-readonly-fetchfiles").longValue(), 11);
    // Test max version
    storesToVersions = getAdminClient().readonlyOps.getROMaxVersion(1, Lists.newArrayList("test-readonly-fetchfiles"));
    assertEquals(storesToVersions.get("test-readonly-fetchfiles").longValue(), 11);
    // Test global max
    storesToVersions = getAdminClient().readonlyOps.getROMaxVersion(Lists.newArrayList("test-readonly-fetchfiles", "test-readonly-versions"));
    assertEquals(storesToVersions.get("test-readonly-fetchfiles").longValue(), 11);
    assertEquals(storesToVersions.get("test-readonly-versions").longValue(), 0);
}
Also used : ReadOnlyStorageEngine(voldemort.store.readonly.ReadOnlyStorageEngine) File(java.io.File) Test(org.junit.Test)

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