Search in sources :

Example 6 with CacheQuota

use of alluxio.client.quota.CacheQuota in project alluxio by Alluxio.

the class LocalCacheManagerTest method putWithInsufficientParentQuota.

@Test
public void putWithInsufficientParentQuota() throws Exception {
    mConf.set(PropertyKey.USER_CLIENT_CACHE_QUOTA_ENABLED, true);
    CacheScope partitionCacheScope1 = CacheScope.create("schema.table.partition1");
    CacheScope partitionCacheScope2 = CacheScope.create("schema.table.partition2");
    CacheScope tableCacheScope = CacheScope.create("schema.table");
    CacheScope schemaCacheScope = CacheScope.create("schema");
    CacheScope[] quotaCacheScopes = { tableCacheScope, schemaCacheScope, CacheScope.GLOBAL };
    for (CacheScope cacheScope : quotaCacheScopes) {
        mMetaStore = new QuotaMetaStore(mConf);
        mPageStore = PageStore.create(PageStoreOptions.create(mConf));
        mCacheManager = createLocalCacheManager(mConf, mMetaStore, mPageStore);
        CacheQuota quota = new CacheQuota(ImmutableMap.of(partitionCacheScope1.level(), (long) PAGE1.length + PAGE2.length, cacheScope.level(), (long) PAGE1.length + PAGE2.length - 1));
        CacheContext context1 = CacheContext.defaults().setCacheScope(partitionCacheScope1).setCacheQuota(quota);
        assertTrue(mCacheManager.put(PAGE_ID1, PAGE1, context1));
        assertEquals(PAGE1.length, mCacheManager.get(PAGE_ID1, PAGE1.length, mBuf, 0));
        CacheContext context2 = CacheContext.defaults().setCacheScope(partitionCacheScope2).setCacheQuota(quota);
        assertTrue(mCacheManager.put(PAGE_ID2, PAGE2, context2));
        assertEquals(0, mCacheManager.get(PAGE_ID1, PAGE1.length, mBuf, 0));
        assertEquals(PAGE2.length, mCacheManager.get(PAGE_ID2, PAGE2.length, mBuf, 0));
    }
}
Also used : CacheContext(alluxio.client.file.CacheContext) CacheScope(alluxio.client.quota.CacheScope) CacheQuota(alluxio.client.quota.CacheQuota) Test(org.junit.Test)

Example 7 with CacheQuota

use of alluxio.client.quota.CacheQuota in project alluxio by Alluxio.

the class LocalCacheManagerWithMemPageStoreTest method putWithQuotaEviction.

@Test
public void putWithQuotaEviction() throws Exception {
    mConf.set(PropertyKey.USER_CLIENT_CACHE_QUOTA_ENABLED, true);
    CacheScope partitionCacheScope = CacheScope.create("schema.table.partition");
    CacheScope tableCacheScope = CacheScope.create("schema.table");
    CacheScope schemaCacheScope = CacheScope.create("schema");
    CacheScope[] quotaCacheScopes = { partitionCacheScope, tableCacheScope, schemaCacheScope, CacheScope.GLOBAL };
    for (CacheScope cacheScope : quotaCacheScopes) {
        mMetaStore = new QuotaMetaStore(mConf);
        mPageStore = PageStore.create(PageStoreOptions.create(mConf));
        mCacheManager = createLocalCacheManager(mConf, mMetaStore, mPageStore);
        CacheQuota quota = new CacheQuota(ImmutableMap.of(cacheScope.level(), (long) PAGE1.length + PAGE2.length - 1));
        CacheContext context = CacheContext.defaults().setCacheScope(partitionCacheScope).setCacheQuota(quota);
        assertTrue(mCacheManager.put(PAGE_ID1, PAGE1, context));
        assertEquals(PAGE1.length, mCacheManager.get(PAGE_ID1, PAGE1.length, mBuf, 0));
        assertTrue(mCacheManager.put(PAGE_ID2, PAGE2, context));
        assertEquals(0, mCacheManager.get(PAGE_ID1, PAGE1.length, mBuf, 0));
        assertEquals(PAGE2.length, mCacheManager.get(PAGE_ID2, PAGE2.length, mBuf, 0));
    }
}
Also used : CacheContext(alluxio.client.file.CacheContext) CacheScope(alluxio.client.quota.CacheScope) CacheQuota(alluxio.client.quota.CacheQuota) Test(org.junit.Test)

Example 8 with CacheQuota

use of alluxio.client.quota.CacheQuota in project alluxio by Alluxio.

the class LocalCacheManagerWithMemPageStoreTest method putWithQuotaMoreThanCacheCapacity.

@Test
public void putWithQuotaMoreThanCacheCapacity() throws Exception {
    mConf.set(PropertyKey.USER_CLIENT_CACHE_QUOTA_ENABLED, true);
    CacheScope partitionCacheScope = CacheScope.create("schema.table.partition");
    CacheScope tableCacheScope = CacheScope.create("schema.table");
    CacheScope schemaCacheScope = CacheScope.create("schema");
    CacheScope[] quotaCacheScopes = { partitionCacheScope, tableCacheScope, schemaCacheScope, CacheScope.GLOBAL };
    for (CacheScope cacheScope : quotaCacheScopes) {
        mMetaStore = new QuotaMetaStore(mConf);
        mPageStore = PageStore.create(PageStoreOptions.create(mConf));
        mCacheManager = createLocalCacheManager(mConf, mMetaStore, mPageStore);
        CacheQuota quota = new CacheQuota(ImmutableMap.of(cacheScope.level(), (long) CACHE_SIZE_BYTES + 1));
        int cacheSize = CACHE_SIZE_BYTES / PAGE_SIZE_BYTES;
        for (int i = 0; i < 2 * cacheSize; i++) {
            PageId pageId = new PageId("3", i);
            CacheContext context = CacheContext.defaults().setCacheScope(partitionCacheScope).setCacheQuota(quota);
            assertTrue(mCacheManager.put(pageId, page(i, PAGE_SIZE_BYTES), context));
            if (i >= cacheSize) {
                assertEquals(0, mCacheManager.get(new PageId("3", i - cacheSize), PAGE_SIZE_BYTES, mBuf, 0));
                // check the subsequent page is still in cache
                assertEquals(true, mMetaStore.hasPage(new PageId("3", i - cacheSize + 1)));
            }
        }
    }
}
Also used : CacheContext(alluxio.client.file.CacheContext) CacheScope(alluxio.client.quota.CacheScope) CacheQuota(alluxio.client.quota.CacheQuota) Test(org.junit.Test)

Example 9 with CacheQuota

use of alluxio.client.quota.CacheQuota in project alluxio by Alluxio.

the class LocalCacheManagerWithMemPageStoreTest method putWithInsufficientParentQuota.

@Test
public void putWithInsufficientParentQuota() throws Exception {
    mConf.set(PropertyKey.USER_CLIENT_CACHE_QUOTA_ENABLED, true);
    CacheScope partitionCacheScope1 = CacheScope.create("schema.table.partition1");
    CacheScope partitionCacheScope2 = CacheScope.create("schema.table.partition2");
    CacheScope tableCacheScope = CacheScope.create("schema.table");
    CacheScope schemaCacheScope = CacheScope.create("schema");
    CacheScope[] quotaCacheScopes = { tableCacheScope, schemaCacheScope, CacheScope.GLOBAL };
    for (CacheScope cacheScope : quotaCacheScopes) {
        mMetaStore = new QuotaMetaStore(mConf);
        mPageStore = PageStore.create(PageStoreOptions.create(mConf));
        mCacheManager = createLocalCacheManager(mConf, mMetaStore, mPageStore);
        CacheQuota quota = new CacheQuota(ImmutableMap.of(partitionCacheScope1.level(), (long) PAGE1.length + PAGE2.length, cacheScope.level(), (long) PAGE1.length + PAGE2.length - 1));
        CacheContext context1 = CacheContext.defaults().setCacheScope(partitionCacheScope1).setCacheQuota(quota);
        assertTrue(mCacheManager.put(PAGE_ID1, PAGE1, context1));
        assertEquals(PAGE1.length, mCacheManager.get(PAGE_ID1, PAGE1.length, mBuf, 0));
        CacheContext context2 = CacheContext.defaults().setCacheScope(partitionCacheScope2).setCacheQuota(quota);
        assertTrue(mCacheManager.put(PAGE_ID2, PAGE2, context2));
        assertEquals(0, mCacheManager.get(PAGE_ID1, PAGE1.length, mBuf, 0));
        assertEquals(PAGE2.length, mCacheManager.get(PAGE_ID2, PAGE2.length, mBuf, 0));
    }
}
Also used : CacheContext(alluxio.client.file.CacheContext) CacheScope(alluxio.client.quota.CacheScope) CacheQuota(alluxio.client.quota.CacheQuota) Test(org.junit.Test)

Example 10 with CacheQuota

use of alluxio.client.quota.CacheQuota in project alluxio by Alluxio.

the class CacheContextTest method setters.

@Test
public void setters() {
    CacheContext context = CacheContext.defaults().setCacheQuota(new CacheQuota()).setCacheScope(CacheScope.create("db.table")).setCacheIdentifier("1234").setHiveCacheContext(new HiveCacheContext("db", "tb", "partition"));
    assertEquals(new CacheQuota(), context.getCacheQuota());
    assertEquals(CacheScope.create("db.table"), context.getCacheScope());
    assertEquals("1234", context.getCacheIdentifier());
    assertEquals(new HiveCacheContext("db", "tb", "partition"), context.getHiveCacheContext());
}
Also used : HiveCacheContext(alluxio.client.hive.HiveCacheContext) HiveCacheContext(alluxio.client.hive.HiveCacheContext) CacheQuota(alluxio.client.quota.CacheQuota) Test(org.junit.Test)

Aggregations

CacheQuota (alluxio.client.quota.CacheQuota)10 CacheScope (alluxio.client.quota.CacheScope)9 Test (org.junit.Test)9 CacheContext (alluxio.client.file.CacheContext)8 HiveCacheContext (alluxio.client.hive.HiveCacheContext)1