private void initSnapshotState(String tableName, File snapshotCacheFolder) { String snapshotID = snapshotCacheFolder.getName(); File stateFile = getCacheStateFile(snapshotCacheFolder.getAbsolutePath()); if (stateFile.exists()) { try { String stateStr = Files.toString(stateFile, Charsets.UTF_8); String resourcePath = ExtTableSnapshotInfo.getResourcePath(tableName, snapshotID); if (CacheState.AVAILABLE.name().equals(stateStr)) { tablesCache.put(resourcePath, new CachedTableInfo(snapshotCacheFolder.getAbsolutePath())); } } catch (IOException e) { logger.error("error to read state file:" + stateFile.getAbsolutePath()); } } }
RestClient restClient = new RestClient(restServer); String stateName = restClient.getLookupSnapshotCacheState(tableName, snapshotID); if (!stateName.equals(CacheState.IN_BUILDING.name())) { completeServers.add(restServer); pw.println("cache build complete for rest server:" + restServer + " cache state:" + stateName);
private void saveSnapshotCacheState(ExtTableSnapshotInfo extTableSnapshotInfo, String cachePath) { File stateFile = getCacheStateFile(getSnapshotCachePath(extTableSnapshotInfo.getTableName(), extTableSnapshotInfo.getId())); try { Files.write(CacheState.AVAILABLE.name(), stateFile, Charsets.UTF_8); tablesCache.put(extTableSnapshotInfo.getResourcePath(), new CachedTableInfo(cachePath)); } catch (IOException e) { throw new RuntimeException("error when write cache state for snapshot:" + extTableSnapshotInfo.getResourcePath()); } }
RestClient restClient = new RestClient(restServer); String stateName = restClient.getLookupSnapshotCacheState(tableName, snapshotID); if (!stateName.equals(CacheState.IN_BUILDING.name())) { completeServers.add(restServer); pw.println("cache build complete for rest server:" + restServer + " cache state:" + stateName);
private void initSnapshotState(String tableName, File snapshotCacheFolder) { String snapshotID = snapshotCacheFolder.getName(); File stateFile = getCacheStateFile(snapshotCacheFolder.getAbsolutePath()); if (stateFile.exists()) { try { String stateStr = Files.toString(stateFile, Charsets.UTF_8); String resourcePath = ExtTableSnapshotInfo.getResourcePath(tableName, snapshotID); if (CacheState.AVAILABLE.name().equals(stateStr)) { tablesCache.put(resourcePath, new CachedTableInfo(snapshotCacheFolder.getAbsolutePath())); } } catch (IOException e) { logger.error("error to read state file:" + stateFile.getAbsolutePath()); } } }
private void saveSnapshotCacheState(ExtTableSnapshotInfo extTableSnapshotInfo, String cachePath) { File stateFile = getCacheStateFile(getSnapshotCachePath(extTableSnapshotInfo.getTableName(), extTableSnapshotInfo.getId())); try { Files.write(CacheState.AVAILABLE.name(), stateFile, Charsets.UTF_8); tablesCache.put(extTableSnapshotInfo.getResourcePath(), new CachedTableInfo(cachePath)); } catch (IOException e) { throw new RuntimeException("error when write cache state for snapshot:" + extTableSnapshotInfo.getResourcePath()); } }
@Test public void testRestoreCacheFromFiles() throws Exception { String snapshotID = RandomUtil.randomUUID().toString(); String snapshotCacheBasePath = RocksDBLookupTableCache.getCacheBasePath(kylinConfig) + File.separator + TABLE_COUNTRY + File.separator + snapshotID; String dbPath = snapshotCacheBasePath + File.separator + "db"; RocksDBLookupBuilder builder = new RocksDBLookupBuilder(tableDesc, new String[] { "COUNTRY" }, dbPath); builder.build(getLookupTableWithRandomData(10000)); String stateFilePath = snapshotCacheBasePath + File.separator + "STATE"; Files.write(CacheState.AVAILABLE.name(), new File(stateFilePath), Charsets.UTF_8); RocksDBLookupTableCache cache = RocksDBLookupTableCache.getInstance(kylinConfig); ExtTableSnapshotInfo snapshotInfo = new ExtTableSnapshotInfo(); snapshotInfo.setTableName(TABLE_COUNTRY); snapshotInfo.setUuid(snapshotID); snapshotInfo.setStorageType(MOCK_EXT_LOOKUP); snapshotInfo.setKeyColumns(new String[] { "COUNTRY" }); ILookupTable lookupTable = cache.getCachedLookupTable(tableDesc, snapshotInfo, false); int rowCnt = 0; for (String[] strings : lookupTable) { rowCnt++; } lookupTable.close(); assertEquals(10000, rowCnt); }
public String getSnapshotLocalCacheState(String tableName, String snapshotID) { ExtTableSnapshotInfoManager snapshotInfoManager = ExtTableSnapshotInfoManager.getInstance(getConfig()); ExtTableSnapshotInfo extTableSnapshotInfo = snapshotInfoManager.getSnapshot(tableName, snapshotID); if (extTableSnapshotInfo == null) { throw new IllegalArgumentException( "cannot find ext snapshot info for table:" + tableName + " snapshot:" + snapshotID); } CacheState cacheState = LookupProviderFactory.getCacheState(extTableSnapshotInfo); return cacheState.name(); }