private void save(SnapshotTable snapshot) throws IOException { ResourceStore store = getStore(); String path = snapshot.getResourcePath(); store.putBigResource(path, snapshot, System.currentTimeMillis(), SnapshotTableSerializer.FULL_SERIALIZER); }
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()); } }
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; }
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; } }
@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); } }
for (Map.Entry<String, String> entry : segment.getSnapshots().entrySet()) { if (entry.getValue().equalsIgnoreCase(item)) { entry.setValue(snapSaved.getResourcePath()); logger.info("Item " + item + " is dup, instead " + snapSaved.getResourcePath() + " is reused");
for (Map.Entry<String, String> entry : segment.getSnapshots().entrySet()) { if (entry.getValue().equalsIgnoreCase(item)) { entry.setValue(snapSaved.getResourcePath()); logger.info("Item " + item + " is dup, instead " + snapSaved.getResourcePath() + " is reused");
response.setSourceTableSize(metaStoreTableSnapshot.getSignature().getSize()); response.setSourceTableLastModifyTime(metaStoreTableSnapshot.getSignature().getLastModifiedTime()); response.setCubesAndSegmentsUsage(snapshotUsageMap.get(metaStoreTableSnapshot.getResourcePath())); result.add(response);
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"));
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 void save(SnapshotTable snapshot) throws IOException { ResourceStore store = MetadataManager.getInstance(this.config).getStore(); String path = snapshot.getResourcePath(); store.putResource(path, snapshot, SnapshotTableSerializer.FULL_SERIALIZER); }
for (Map.Entry<String, String> entry : segment.getSnapshots().entrySet()) { if (entry.getValue().equalsIgnoreCase(item)) { entry.setValue(snapSaved.getResourcePath()); logger.info("Item " + item + " is dup, instead " + snapSaved.getResourcePath() + " is reused");
public SnapshotTable buildSnapshotTable(CubeSegment cubeSeg, String lookupTable) throws IOException { MetadataManager metaMgr = getMetadataManager(); SnapshotManager snapshotMgr = getSnapshotManager(); HiveTable hiveTable = new HiveTable(metaMgr, lookupTable); TableDesc tableDesc = metaMgr.getTableDesc(lookupTable); SnapshotTable snapshot = snapshotMgr.buildSnapshot(hiveTable, tableDesc); cubeSeg.putSnapshotResPath(lookupTable, snapshot.getResourcePath()); saveResource(cubeSeg.getCubeInstance()); return snapshot; }
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 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 void save(SnapshotTable snapshot) throws IOException { ResourceStore store = MetadataManager.getInstance(this.config).getStore(); String path = snapshot.getResourcePath(); store.putResource(path, snapshot, SnapshotTableSerializer.FULL_SERIALIZER); }
@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 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; }
public SnapshotTable buildSnapshotTable(CubeSegment cubeSeg, String lookupTable) throws IOException { MetadataManager metaMgr = getMetadataManager(); SnapshotManager snapshotMgr = getSnapshotManager(); HiveTable hiveTable = new HiveTable(metaMgr, lookupTable); TableDesc tableDesc = metaMgr.getTableDesc(lookupTable); SnapshotTable snapshot = snapshotMgr.buildSnapshot(hiveTable, tableDesc); cubeSeg.putSnapshotResPath(lookupTable, snapshot.getResourcePath()); saveResource(cubeSeg.getCubeInstance()); return snapshot; }