Search in sources :

Example 1 with QuotaType

use of voldemort.store.quota.QuotaType in project voldemort by voldemort.

the class AdminServiceBasicTest method testRebalanceQuota.

@Test
public void testRebalanceQuota() throws InterruptedException {
    AdminClient client = getAdminClient();
    String storeName = storeDefs.get(0).getName();
    QuotaType quotaType = QuotaType.GET_THROUGHPUT;
    Long quota = 1000L, targetQuota = quota / 2;
    client.quotaMgmtOps.setQuotaForNode(storeName, quotaType, 0, quota);
    client.quotaMgmtOps.rebalanceQuota(storeName, quotaType);
    // rebalanceQuota use put. Put completes as soon as the required nodes
    // are completed and rest of them are done in async. There is a race
    // condition here if you poll too soon you will see inconsistent result,
    // as some of the puts are still in async. Sleep here to avoid those
    // conditions.
    Thread.sleep(100);
    Long getQuota0 = Long.parseLong(client.quotaMgmtOps.getQuotaForNode(storeName, quotaType, 0).getValue());
    Long getQuota1 = Long.parseLong(client.quotaMgmtOps.getQuotaForNode(storeName, quotaType, 1).getValue());
    assertEquals(targetQuota, getQuota0);
    assertEquals(targetQuota, getQuota1);
}
Also used : QuotaType(voldemort.store.quota.QuotaType) AdminClient(voldemort.client.protocol.admin.AdminClient) Test(org.junit.Test)

Example 2 with QuotaType

use of voldemort.store.quota.QuotaType in project voldemort by voldemort.

the class VerifyOrAddStoreTest method verifyNewStoreAddition.

@Test
public void verifyNewStoreAddition() {
    adminClient.storeMgmtOps.verifyOrAddStore(newStoreDef, PROCESS_NAME, service);
    verifyStoreAddedOnAllNodes();
    // Verify set quota on the stores as well.
    for (QuotaType quotaType : new QuotaType[] { QuotaType.STORAGE_SPACE, QuotaType.GET_THROUGHPUT }) {
        long newQuota = 100000 + new Random().nextInt(10000);
        adminClient.quotaMgmtOps.setQuota(newStoreName, quotaType, newQuota, service);
        for (Integer nodeId : cluster.getNodeIds()) {
            Long retrievedQuota = getQuotaForNode(newStoreName, quotaType, nodeId);
            assertEquals("Set and retrieved different quota", newQuota, retrievedQuota.longValue());
        }
    }
}
Also used : Random(java.util.Random) QuotaType(voldemort.store.quota.QuotaType) Test(org.junit.Test)

Example 3 with QuotaType

use of voldemort.store.quota.QuotaType in project voldemort by voldemort.

the class ExceededQuotaSlopTest method setGetPutQuotasForEachServer.

public void setGetPutQuotasForEachServer() throws Exception {
    Properties adminProperties = new Properties();
    adminProperties.setProperty("max_connections", "2");
    adminClient = new AdminClient(cluster, new AdminClientConfig().setMaxConnectionsPerNode(2));
    Map<Pair<Integer, QuotaType>, Integer> throughPutMap = new HashMap<Pair<Integer, QuotaType>, Integer>();
    // Set Node0 Quota
    throughPutMap.put(new Pair<Integer, QuotaType>(0, QuotaType.PUT_THROUGHPUT), 5);
    throughPutMap.put(new Pair<Integer, QuotaType>(0, QuotaType.GET_THROUGHPUT), 20);
    // Set Node1 Quota
    throughPutMap.put(new Pair<Integer, QuotaType>(1, QuotaType.PUT_THROUGHPUT), 2);
    throughPutMap.put(new Pair<Integer, QuotaType>(1, QuotaType.GET_THROUGHPUT), 20);
    for (Entry<Pair<Integer, QuotaType>, Integer> throughPut : throughPutMap.entrySet()) {
        int nodeId = throughPut.getKey().getFirst();
        QuotaType type = throughPut.getKey().getSecond();
        int value = throughPut.getValue();
        VectorClock clock = VectorClockUtils.makeClockWithCurrentTime(cluster.getNodeIds());
        NodeValue<ByteArray, byte[]> operationValue = new NodeValue<ByteArray, byte[]>(nodeId, new ByteArray(getKeyBytes(type)), new Versioned<byte[]>(ByteUtils.getBytes(Integer.toString(value), encodingType), clock));
        try {
            adminClient.storeOps.putNodeKeyValue(quotaStoreName, operationValue);
        } catch (Exception e) {
            throw new Exception("Exception when setting put quota for node " + nodeId + " Operation " + type + "." + e.getMessage());
        }
    }
}
Also used : NodeValue(voldemort.store.routed.NodeValue) AdminClientConfig(voldemort.client.protocol.admin.AdminClientConfig) HashMap(java.util.HashMap) QuotaType(voldemort.store.quota.QuotaType) VectorClock(voldemort.versioning.VectorClock) Properties(java.util.Properties) VoldemortException(voldemort.VoldemortException) IOException(java.io.IOException) ByteArray(voldemort.utils.ByteArray) AdminClient(voldemort.client.protocol.admin.AdminClient) Pair(voldemort.utils.Pair)

Example 4 with QuotaType

use of voldemort.store.quota.QuotaType in project voldemort by voldemort.

the class QuotaOperationsTest method testQuotaSetAndUnset.

@Test
public void testQuotaSetAndUnset() throws Exception {
    for (QuotaType quotaType : QuotaType.values()) {
        String quotaValueToSet = "1000";
        // set quota value
        AdminCommand.executeCommand(new String[] { "quota", "set", quotaType + "=" + quotaValueToSet, "-s", storeName, "-u", bsURL, "--confirm" });
        // get quota value
        String quotaValueToVerify = adminClient.quotaMgmtOps.getQuota(storeName, quotaType).getValue();
        assertTrue(quotaValueToVerify.equals(quotaValueToSet));
        // unset quota value
        AdminCommand.executeCommand(new String[] { "quota", "unset", quotaType.toString(), "-s", storeName, "-u", bsURL, "--confirm" });
        // get quota value
        Versioned<String> versionedQuotaValueToVerify = adminClient.quotaMgmtOps.getQuota(storeName, quotaType);
        assertNull("Value retrieved should be null" + versionedQuotaValueToVerify, versionedQuotaValueToVerify);
    }
}
Also used : QuotaType(voldemort.store.quota.QuotaType) Test(org.junit.Test)

Example 5 with QuotaType

use of voldemort.store.quota.QuotaType in project voldemort by voldemort.

the class AdminToolUtils method getQuotaTypes.

/**
     * Utility function that fetches quota types.
     */
public static List<QuotaType> getQuotaTypes(List<String> strQuotaTypes) {
    if (strQuotaTypes.size() < 1) {
        throw new VoldemortException("Quota type not specified.");
    }
    List<QuotaType> quotaTypes;
    if (strQuotaTypes.size() == 1 && strQuotaTypes.get(0).equals(AdminToolUtils.QUOTATYPE_ALL)) {
        quotaTypes = Arrays.asList(QuotaType.values());
    } else {
        quotaTypes = new ArrayList<QuotaType>();
        for (String strQuotaType : strQuotaTypes) {
            QuotaType type = QuotaType.valueOf(strQuotaType);
            quotaTypes.add(type);
        }
    }
    return quotaTypes;
}
Also used : QuotaType(voldemort.store.quota.QuotaType) VoldemortException(voldemort.VoldemortException)

Aggregations

QuotaType (voldemort.store.quota.QuotaType)9 Test (org.junit.Test)7 Random (java.util.Random)5 VoldemortException (voldemort.VoldemortException)4 StoreDefinition (voldemort.store.StoreDefinition)3 HashMap (java.util.HashMap)2 AdminClient (voldemort.client.protocol.admin.AdminClient)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 AdminClientConfig (voldemort.client.protocol.admin.AdminClientConfig)1 NodeValue (voldemort.store.routed.NodeValue)1 ByteArray (voldemort.utils.ByteArray)1 Pair (voldemort.utils.Pair)1 VectorClock (voldemort.versioning.VectorClock)1