use of alluxio.client.quota.CacheScope in project alluxio by Alluxio.
the class LocalCacheManagerWithMemPageStoreTest method putWithInsufficientQuota.
@Test
public void putWithInsufficientQuota() throws Exception {
mConf.set(PropertyKey.USER_CLIENT_CACHE_QUOTA_ENABLED, true);
mMetaStore = new QuotaMetaStore(mConf);
mCacheManager = createLocalCacheManager(mConf, mMetaStore, mPageStore);
CacheScope scope = CacheScope.create("schema.table.partition");
CacheContext context = CacheContext.defaults().setCacheScope(scope);
// insufficient partition quota
assertFalse(mCacheManager.put(PAGE_ID1, PAGE1, context.setCacheQuota(new CacheQuota(ImmutableMap.of(CacheScope.Level.PARTITION, (long) PAGE1.length - 1)))));
// insufficient table quota
assertFalse(mCacheManager.put(PAGE_ID1, PAGE1, context.setCacheQuota(new CacheQuota(ImmutableMap.of(CacheScope.Level.TABLE, (long) PAGE1.length - 1)))));
// insufficient schema quota
assertFalse(mCacheManager.put(PAGE_ID1, PAGE1, context.setCacheQuota(new CacheQuota(ImmutableMap.of(CacheScope.Level.SCHEMA, (long) PAGE1.length - 1)))));
// insufficient global quota
assertFalse(mCacheManager.put(PAGE_ID1, PAGE1, context.setCacheQuota(new CacheQuota(ImmutableMap.of(CacheScope.Level.GLOBAL, (long) PAGE1.length - 1)))));
// without quota
assertTrue(mCacheManager.put(PAGE_ID1, PAGE1));
}
use of alluxio.client.quota.CacheScope in project alluxio by Alluxio.
the class QuotaMetaStoreTest method evictInScope2.
@Test
public void evictInScope2() throws Exception {
CacheScope partitionScope1 = CacheScope.create("schema.table.partition1");
CacheScope partitionScope2 = CacheScope.create("schema.table.partition2");
PageId pageId1 = new PageId("1L", 2L);
PageId pageId2 = new PageId("3L", 4L);
PageInfo pageInfo1 = new PageInfo(pageId1, 1234, partitionScope1);
PageInfo pageInfo2 = new PageInfo(pageId2, 5678, partitionScope2);
mQuotaMetaStore.addPage(pageId1, pageInfo1);
mQuotaMetaStore.addPage(pageId2, pageInfo2);
assertEquals(pageInfo1, mQuotaMetaStore.evict(partitionScope1));
assertEquals(pageInfo2, mQuotaMetaStore.evict(partitionScope2));
PageInfo evicted = mQuotaMetaStore.evict(mTableScope);
assertTrue(evicted == pageInfo1 || evicted == pageInfo2);
evicted = mQuotaMetaStore.evict(mSchemaScope);
assertTrue(evicted == pageInfo1 || evicted == pageInfo2);
evicted = mQuotaMetaStore.evict(CacheScope.GLOBAL);
assertTrue(evicted == pageInfo1 || evicted == pageInfo2);
mQuotaMetaStore.removePage(pageId1);
assertNull(mQuotaMetaStore.evict(partitionScope1));
assertEquals(pageInfo2, mQuotaMetaStore.evict(partitionScope2));
assertEquals(pageInfo2, mQuotaMetaStore.evict(mTableScope));
assertEquals(pageInfo2, mQuotaMetaStore.evict(mSchemaScope));
assertEquals(pageInfo2, mQuotaMetaStore.evict(CacheScope.GLOBAL));
}
use of alluxio.client.quota.CacheScope in project alluxio by Alluxio.
the class LocalCacheManagerTest method putWithInsufficientQuota.
@Test
public void putWithInsufficientQuota() throws Exception {
mConf.set(PropertyKey.USER_CLIENT_CACHE_QUOTA_ENABLED, true);
mMetaStore = new QuotaMetaStore(mConf);
mCacheManager = createLocalCacheManager(mConf, mMetaStore, mPageStore);
CacheScope scope = CacheScope.create("schema.table.partition");
CacheContext context = CacheContext.defaults().setCacheScope(scope);
// insufficient partition quota
assertFalse(mCacheManager.put(PAGE_ID1, PAGE1, context.setCacheQuota(new CacheQuota(ImmutableMap.of(CacheScope.Level.PARTITION, (long) PAGE1.length - 1)))));
// insufficient table quota
assertFalse(mCacheManager.put(PAGE_ID1, PAGE1, context.setCacheQuota(new CacheQuota(ImmutableMap.of(CacheScope.Level.TABLE, (long) PAGE1.length - 1)))));
// insufficient schema quota
assertFalse(mCacheManager.put(PAGE_ID1, PAGE1, context.setCacheQuota(new CacheQuota(ImmutableMap.of(CacheScope.Level.SCHEMA, (long) PAGE1.length - 1)))));
// insufficient global quota
assertFalse(mCacheManager.put(PAGE_ID1, PAGE1, context.setCacheQuota(new CacheQuota(ImmutableMap.of(CacheScope.Level.GLOBAL, (long) PAGE1.length - 1)))));
// without quota
assertTrue(mCacheManager.put(PAGE_ID1, PAGE1));
}
use of alluxio.client.quota.CacheScope in project alluxio by Alluxio.
the class LocalCacheManagerTest 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)));
}
}
}
}
use of alluxio.client.quota.CacheScope 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));
}
}
Aggregations