private SnapshotManager getSnapshotManager() { return SnapshotManager.getInstance(config); }
public SnapshotTable buildSnapshot(IReadableTable table, TableDesc tableDesc, KylinConfig cubeConfig) throws IOException { SnapshotTable snapshot = new SnapshotTable(table, tableDesc.getIdentity()); snapshot.updateRandomUuid(); String dup = checkDupByInfo(snapshot); if (dup != null) { logger.info("Identical input " + table.getSignature() + ", reuse existing snapshot at " + dup); return getSnapshotTable(dup); } if ((float) snapshot.getSignature().getSize() / 1024 / 1024 > cubeConfig.getTableSnapshotMaxMB()) { throw new IllegalStateException("Table snapshot should be no greater than " + cubeConfig.getTableSnapshotMaxMB() // + " MB, but " + tableDesc + " size is " + snapshot.getSignature().getSize()); } snapshot.takeSnapshot(table, tableDesc); return trySaveNewSnapshot(snapshot); }
static SnapshotManager newInstance(KylinConfig config) throws IOException { return new SnapshotManager(config); }
public SnapshotTable trySaveNewSnapshot(SnapshotTable snapshotTable) throws IOException { String dupTable = checkDupByContent(snapshotTable); if (dupTable != null) { logger.info("Identical snapshot content " + snapshotTable + ", reuse existing snapshot at " + dupTable); return getSnapshotTable(dupTable); } save(snapshotTable); snapshotCache.put(snapshotTable.getResourcePath(), snapshotTable); return snapshotTable; }
private static void rebuild(String table, String overwriteUUID, String project) throws IOException { KylinConfig conf = KylinConfig.getInstanceFromEnv(); TableMetadataManager metaMgr = TableMetadataManager.getInstance(conf); SnapshotManager snapshotMgr = SnapshotManager.getInstance(conf); TableDesc tableDesc = metaMgr.getTableDesc(table, project); if (tableDesc == null) throw new IllegalArgumentException("Not table found by " + table); if (tableDesc.isView()) throw new IllegalArgumentException("Build snapshot of hive view \'" + table + "\' not supported."); SnapshotTable snapshot = snapshotMgr.rebuildSnapshot(SourceManager.createReadableTable(tableDesc, null), tableDesc, overwriteUUID); System.out.println("resource path updated: " + snapshot.getResourcePath()); } }
SnapshotManager dstSnapMgr = SnapshotManager.getInstance(dstConfig); SnapshotManager srcSnapMgr = SnapshotManager.getInstance(srcConfig); SnapshotTable snapSrc = srcSnapMgr.getSnapshotTable(item); SnapshotTable snapSaved = dstSnapMgr.trySaveNewSnapshot(snapSrc); snapSrc.setLastModified(ts);
private ILookupTable getInMemLookupTable(CubeSegment cubeSegment, JoinDesc join, SnapshotTableDesc snapshotTableDesc) { String tableName = join.getPKSide().getTableIdentity(); String snapshotResPath = getSnapshotResPath(cubeSegment, tableName, snapshotTableDesc); String[] pkCols = join.getPrimaryKey(); try { SnapshotTable snapshot = getSnapshotManager().getSnapshotTable(snapshotResPath); TableDesc tableDesc = getMetadataManager().getTableDesc(tableName, cubeSegment.getProject()); return LookupProviderFactory.getInMemLookupTable(tableDesc, pkCols, snapshot); } catch (IOException e) { throw new IllegalStateException( "Failed to load lookup table " + tableName + " from snapshot " + snapshotResPath, e); } }
@Override protected ExecuteResult doWork(ExecutableContext context) throws ExecuteException { KylinConfig kylinConfig = context.getConfig(); CubeManager cubeManager = CubeManager.getInstance(kylinConfig); TableMetadataManager metaMgr = TableMetadataManager.getInstance(kylinConfig); SnapshotManager snapshotMgr = SnapshotManager.getInstance(kylinConfig); CubeInstance cube = cubeManager.getCube(LookupExecutableUtil.getCubeName(this.getParams())); List<String> segmentIDs = LookupExecutableUtil.getSegments(this.getParams()); String lookupTableName = LookupExecutableUtil.getLookupTableName(this.getParams()); CubeDesc cubeDesc = cube.getDescriptor(); try { TableDesc tableDesc = metaMgr.getTableDesc(lookupTableName, cube.getProject()); IReadableTable hiveTable = SourceManager.createReadableTable(tableDesc, null); logger.info("take snapshot for table:" + lookupTableName); SnapshotTable snapshot = snapshotMgr.buildSnapshot(hiveTable, tableDesc, cube.getConfig()); logger.info("update snapshot path to cube metadata"); if (cubeDesc.isGlobalSnapshotTable(lookupTableName)) { LookupExecutableUtil.updateSnapshotPathToCube(cubeManager, cube, lookupTableName, snapshot.getResourcePath()); } else { LookupExecutableUtil.updateSnapshotPathToSegments(cubeManager, cube, segmentIDs, lookupTableName, snapshot.getResourcePath()); } return new ExecuteResult(); } catch (IOException e) { logger.error("fail to build snapshot for:" + lookupTableName, e); return ExecuteResult.createError(e); } }
public SnapshotTable rebuildSnapshot(IReadableTable table, TableDesc tableDesc, String overwriteUUID) throws IOException { SnapshotTable snapshot = new SnapshotTable(table, tableDesc.getIdentity()); snapshot.setUuid(overwriteUUID); snapshot.takeSnapshot(table, tableDesc); SnapshotTable existing = getSnapshotTable(snapshot.getResourcePath()); snapshot.setLastModified(existing.getLastModified()); save(snapshot); snapshotCache.put(snapshot.getResourcePath(), snapshot); return snapshot; }
List<TableSnapshotResponse> internalGetLookupTableSnapshots(String tableName, TableSignature signature) throws IOException { ExtTableSnapshotInfoManager extSnapshotInfoManager = ExtTableSnapshotInfoManager.getInstance(getConfig()); SnapshotManager snapshotManager = SnapshotManager.getInstance(getConfig()); List<ExtTableSnapshotInfo> extTableSnapshots = extSnapshotInfoManager.getSnapshots(tableName); List<SnapshotTable> metaStoreTableSnapshots = snapshotManager.getSnapshots(tableName, signature);
@Test public void basicTest() throws Exception { String tableName = "EDW.TEST_SITES"; HiveTable hiveTable = new HiveTable(MetadataManager.getInstance(getTestConfig()), tableName); TableDesc tableDesc = MetadataManager.getInstance(getTestConfig()).getTableDesc(tableName); String snapshotPath = snapshotMgr.buildSnapshot(hiveTable, tableDesc).getResourcePath(); snapshotMgr.wipeoutCache(); SnapshotTable snapshot = snapshotMgr.getSnapshotTable(snapshotPath); // compare hive & snapshot TableReader hiveReader = hiveTable.getReader(); TableReader snapshotReader = snapshot.getReader(); while (true) { boolean hiveNext = hiveReader.next(); boolean snapshotNext = snapshotReader.next(); assertEquals(hiveNext, snapshotNext); if (hiveNext == false) break; String[] hiveRow = hiveReader.getRow(); String[] snapshotRow = snapshotReader.getRow(); assertArrayEquals(hiveRow, snapshotRow); } } }
public SnapshotTable buildSnapshotTable(CubeSegment cubeSeg, String lookupTable, String uuid) throws IOException { // work on copy instead of cached objects CubeInstance cubeCopy = cubeSeg.getCubeInstance().latestCopyForWrite(); // get a latest copy CubeSegment segCopy = cubeCopy.getSegmentById(cubeSeg.getUuid()); TableMetadataManager metaMgr = getTableManager(); SnapshotManager snapshotMgr = getSnapshotManager(); TableDesc tableDesc = new TableDesc(metaMgr.getTableDesc(lookupTable, segCopy.getProject())); IReadableTable hiveTable = SourceManager.createReadableTable(tableDesc, uuid); SnapshotTable snapshot = snapshotMgr.buildSnapshot(hiveTable, tableDesc, cubeSeg.getConfig()); CubeDesc cubeDesc = cubeSeg.getCubeDesc(); if (!cubeDesc.isGlobalSnapshotTable(lookupTable)) { segCopy.putSnapshotResPath(lookupTable, snapshot.getResourcePath()); CubeUpdate update = new CubeUpdate(cubeCopy); update.setToUpdateSegs(segCopy); updateCube(update); // Update the input cubeSeg after the resource store updated cubeSeg.putSnapshotResPath(lookupTable, segCopy.getSnapshotResPath(lookupTable)); } else { CubeUpdate cubeUpdate = new CubeUpdate(cubeCopy); Map<String, String> map = Maps.newHashMap(); map.put(lookupTable, snapshot.getResourcePath()); cubeUpdate.setUpdateTableSnapshotPath(map); updateCube(cubeUpdate); cubeSeg.getCubeInstance().putSnapshotResPath(lookupTable, snapshot.getResourcePath()); } return snapshot; } }
SnapshotManager dstSnapMgr = SnapshotManager.getInstance(dstConfig); SnapshotManager srcSnapMgr = SnapshotManager.getInstance(srcConfig); SnapshotTable snapSrc = srcSnapMgr.getSnapshotTable(item); SnapshotTable snapSaved = dstSnapMgr.trySaveNewSnapshot(snapSrc); snapSrc.setLastModified(ts);
public SnapshotTable trySaveNewSnapshot(SnapshotTable snapshotTable) throws IOException { String dupTable = checkDupByContent(snapshotTable); if (dupTable != null) { logger.info("Identical snapshot content " + snapshotTable + ", reuse existing snapshot at " + dupTable); return getSnapshotTable(dupTable); } save(snapshotTable); snapshotCache.put(snapshotTable.getResourcePath(), snapshotTable); return snapshotTable; }
public LookupTable<String> initLookupTable() throws Exception { TableMetadataManager metaMgr = TableMetadataManager.getInstance(config); String tableName = "EDW.TEST_CAL_DT"; String[] pkCols = new String[] { "CAL_DT" }; String snapshotResPath = "/table_snapshot/TEST_CAL_DT.csv/4af48c94-86de-4e22-a4fd-c49b06cbaa4f.snapshot"; SnapshotTable snapshot = getSnapshotManager().getSnapshotTable(snapshotResPath); TableDesc tableDesc = metaMgr.getTableDesc(tableName, "default"); LookupTable<String> lt = new LookupStringTable(tableDesc, pkCols, snapshot); System.out.println(lt); return lt; }
@Override protected ExecuteResult doWork(ExecutableContext context) throws ExecuteException { KylinConfig kylinConfig = context.getConfig(); CubeManager cubeManager = CubeManager.getInstance(kylinConfig); TableMetadataManager metaMgr = TableMetadataManager.getInstance(kylinConfig); SnapshotManager snapshotMgr = SnapshotManager.getInstance(kylinConfig); CubeInstance cube = cubeManager.getCube(LookupExecutableUtil.getCubeName(this.getParams())); List<String> segmentIDs = LookupExecutableUtil.getSegments(this.getParams()); String lookupTableName = LookupExecutableUtil.getLookupTableName(this.getParams()); CubeDesc cubeDesc = cube.getDescriptor(); try { TableDesc tableDesc = metaMgr.getTableDesc(lookupTableName, cube.getProject()); IReadableTable hiveTable = SourceManager.createReadableTable(tableDesc, null); logger.info("take snapshot for table:" + lookupTableName); SnapshotTable snapshot = snapshotMgr.buildSnapshot(hiveTable, tableDesc, cube.getConfig()); logger.info("update snapshot path to cube metadata"); if (cubeDesc.isGlobalSnapshotTable(lookupTableName)) { LookupExecutableUtil.updateSnapshotPathToCube(cubeManager, cube, lookupTableName, snapshot.getResourcePath()); } else { LookupExecutableUtil.updateSnapshotPathToSegments(cubeManager, cube, segmentIDs, lookupTableName, snapshot.getResourcePath()); } return new ExecuteResult(); } catch (IOException e) { logger.error("fail to build snapshot for:" + lookupTableName, e); return ExecuteResult.createError(e); } }
public SnapshotTable rebuildSnapshot(IReadableTable table, TableDesc tableDesc, String overwriteUUID) throws IOException { SnapshotTable snapshot = new SnapshotTable(table, tableDesc.getIdentity()); snapshot.setUuid(overwriteUUID); snapshot.takeSnapshot(table, tableDesc); SnapshotTable existing = getSnapshotTable(snapshot.getResourcePath()); snapshot.setLastModified(existing.getLastModified()); save(snapshot); snapshotCache.put(snapshot.getResourcePath(), snapshot); return snapshot; }
private static void rebuild(String table, String overwriteUUID, String project) throws IOException { KylinConfig conf = KylinConfig.getInstanceFromEnv(); TableMetadataManager metaMgr = TableMetadataManager.getInstance(conf); SnapshotManager snapshotMgr = SnapshotManager.getInstance(conf); TableDesc tableDesc = metaMgr.getTableDesc(table, project); if (tableDesc == null) throw new IllegalArgumentException("Not table found by " + table); if (tableDesc.isView()) throw new IllegalArgumentException("Build snapshot of hive view \'" + table + "\' not supported."); SnapshotTable snapshot = snapshotMgr.rebuildSnapshot(SourceManager.createReadableTable(tableDesc, null), tableDesc, overwriteUUID); System.out.println("resource path updated: " + snapshot.getResourcePath()); } }
SnapshotManager snapshotManager = getSnapshotManager(); try { snapshotManager.buildSnapshot(mockTable, tableDesc, cubeConfig).getResourcePath(); } catch (IllegalStateException ex) { Assert.assertTrue(ex.getLocalizedMessage().startsWith("Table snapshot should be no greater than 0 MB"));
SnapshotManager dstSnapMgr = SnapshotManager.getInstance(dstConfig); SnapshotManager srcSnapMgr = SnapshotManager.getInstance(srcConfig); SnapshotTable snapSrc = srcSnapMgr.getSnapshotTable(item); SnapshotTable snapSaved = dstSnapMgr.trySaveNewSnapshot(snapSrc); snapSrc.setLastModified(ts);