private void removeSnapshotIfExist(ExtTableSnapshotInfoManager extSnapshotInfoManager, KylinConfig kylinConfig, String tableName, String lookupSnapshotID) throws IOException { ExtTableSnapshotInfo snapshotInfo = null; try { snapshotInfo = extSnapshotInfoManager.getSnapshot(tableName, lookupSnapshotID); } catch (Exception e) { // swallow the exception, means not snapshot exist of this snapshot id } if (snapshotInfo == null) { return; } logger.info("the table:{} snapshot:{} exist, remove it", tableName, lookupSnapshotID); extSnapshotInfoManager.removeSnapshot(tableName, lookupSnapshotID); String hTableName = snapshotInfo.getStorageLocationIdentifier(); logger.info("remove related HBase table:{} for snapshot:{}", hTableName, lookupSnapshotID); Connection conn = getHBaseConnection(kylinConfig); Admin admin = conn.getAdmin(); admin.deleteTable(TableName.valueOf(hTableName)); }
@Test public void testCheckCacheState() throws Exception { ExtTableSnapshotInfo snapshotInfo = buildSnapshotCache(RandomUtil.randomUUID().toString(), 1000); RocksDBLookupTableCache cache = RocksDBLookupTableCache.getInstance(kylinConfig); ILookupTable cachedLookupTable = cache.getCachedLookupTable(tableDesc, snapshotInfo, false); assertNotNull(cachedLookupTable); cachedLookupTable.close(); ExtTableSnapshotInfoManager.getInstance(kylinConfig).removeSnapshot(snapshotInfo.getTableName(), snapshotInfo.getId()); cache.checkCacheState(); String cacheLocalPath = cache.getSnapshotCachePath(snapshotInfo.getTableName(), snapshotInfo.getId()); // won't cleanup because it is newly created in last 1 hour assertTrue(new File(cacheLocalPath).exists()); // change the volatile value kylinConfig.setProperty("kylin.snapshot.ext.local.cache.check.volatile", "0"); cache.checkCacheState(); // this time it should be removed. assertFalse(new File(cacheLocalPath).exists()); cachedLookupTable = cache.getCachedLookupTable(tableDesc, snapshotInfo, false); assertNull(cachedLookupTable); }
private void removeSnapshotIfExist(ExtTableSnapshotInfoManager extSnapshotInfoManager, KylinConfig kylinConfig, String tableName, String lookupSnapshotID) throws IOException { ExtTableSnapshotInfo snapshotInfo = null; try { snapshotInfo = extSnapshotInfoManager.getSnapshot(tableName, lookupSnapshotID); } catch (Exception e) { // swallow the exception, means not snapshot exist of this snapshot id } if (snapshotInfo == null) { return; } logger.info("the table:{} snapshot:{} exist, remove it", tableName, lookupSnapshotID); extSnapshotInfoManager.removeSnapshot(tableName, lookupSnapshotID); String hTableName = snapshotInfo.getStorageLocationIdentifier(); logger.info("remove related HBase table:{} for snapshot:{}", hTableName, lookupSnapshotID); Connection conn = getHBaseConnection(kylinConfig); Admin admin = conn.getAdmin(); admin.deleteTable(TableName.valueOf(hTableName)); }