/** * Get table config value for a key * @param tableId Id of the table * @param key Key for the config item * @return config value for the key */ public String getForTable(String tableId, String key) { return getForTable(tableId, key, null); }
private <T> T deserializeObject(JavaTableConfig tableConfig, String key) { String entry = tableConfig.getForTable(tableId, key, ""); if (entry.isEmpty()) { return null; } return SerdeUtils.deserialize(key, entry); }
private ReadWriteTable createDefaultCacheTable(String tableId, JavaTableConfig tableConfig) { long readTtlMs = Long.parseLong(tableConfig.getForTable(tableId, CachingTableDescriptor.READ_TTL_MS, "-1")); long writeTtlMs = Long.parseLong(tableConfig.getForTable(tableId, CachingTableDescriptor.WRITE_TTL_MS, "-1")); long cacheSize = Long.parseLong(tableConfig.getForTable(tableId, CachingTableDescriptor.CACHE_SIZE, "-1")); CacheBuilder cacheBuilder = CacheBuilder.newBuilder(); if (readTtlMs != -1) { cacheBuilder.expireAfterAccess(readTtlMs, TimeUnit.MILLISECONDS); } if (writeTtlMs != -1) { cacheBuilder.expireAfterWrite(writeTtlMs, TimeUnit.MILLISECONDS); } if (cacheSize != -1) { cacheBuilder.maximumSize(cacheSize); } logger.info(String.format("Creating default cache with: readTtl=%d, writeTtl=%d, maxSize=%d", readTtlMs, writeTtlMs, cacheSize)); GuavaCacheTable cacheTable = new GuavaCacheTable(tableId + "-def-cache", cacheBuilder.build()); cacheTable.init(this.context); return cacheTable; } }
@Override public ReadWriteTable getTable() { Preconditions.checkNotNull(context, String.format("Table %s not initialized", tableId)); JavaTableConfig tableConfig = new JavaTableConfig(context.getJobContext().getConfig()); Cache guavaCache = SerdeUtils.deserialize(GuavaCacheTableDescriptor.GUAVA_CACHE, tableConfig.getForTable(tableId, GuavaCacheTableDescriptor.GUAVA_CACHE)); GuavaCacheTable table = new GuavaCacheTable(tableId, guavaCache); table.init(this.context); guavaTables.add(table); return table; }
@Override public ReadWriteTable getTable() { Preconditions.checkNotNull(context, String.format("Table %s not initialized", tableId)); JavaTableConfig tableConfig = new JavaTableConfig(context.getJobContext().getConfig()); String realTableId = tableConfig.getForTable(tableId, CachingTableDescriptor.REAL_TABLE_ID); ReadWriteTable table = this.context.getTaskContext().getTable(realTableId); String cacheTableId = tableConfig.getForTable(tableId, CachingTableDescriptor.CACHE_TABLE_ID); ReadWriteTable cache; if (cacheTableId != null) { cache = this.context.getTaskContext().getTable(cacheTableId); } else { cache = createDefaultCacheTable(realTableId, tableConfig); defaultCaches.add(cache); } boolean isWriteAround = Boolean.parseBoolean(tableConfig.getForTable(tableId, CachingTableDescriptor.WRITE_AROUND)); CachingTable cachingTable = new CachingTable(tableId, table, cache, isWriteAround); cachingTable.init(this.context); return cachingTable; }
@Test public void testGetForTable() { Map<String, String> map = new HashMap<>(); map.put(JavaTableConfig.buildKey("t1", "abc"), "xyz"); JavaTableConfig tableConfig = new JavaTableConfig(new MapConfig(map)); Assert.assertEquals("xyz", tableConfig.getForTable("t1", "abc")); Assert.assertNull(tableConfig.getForTable("t1", "aaa")); Assert.assertEquals("xyz", tableConfig.getForTable("t1", "aaa", "xyz")); Assert.assertNull(tableConfig.getForTable("tt", "abc")); Assert.assertEquals("xyz", tableConfig.getForTable("tt", "abc", "xyz")); } }
int callbackPoolSize = Integer.parseInt(tableConfig.getForTable(tableId, RemoteTableDescriptor.ASYNC_CALLBACK_POOL_SIZE, "-1")); if (callbackPoolSize > 0) { callbackExecutors.computeIfAbsent(tableId, (arg) ->