Skip to content

Commit

Permalink
KYLIN-3994: StorageCleanupJob may delete cube id data of new built se…
Browse files Browse the repository at this point in the history
…gment because of cube cache in CubeManager (apache#633)

* KYLIN-3994: StorageCleanupJob may delete cube id data of new built segment because of cube cache in CubeManager
  • Loading branch information
lshmouse authored and nichunen committed May 31, 2019
1 parent 670c2a9 commit cfce8bb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
16 changes: 16 additions & 0 deletions core-cube/src/main/java/org/apache/kylin/cube/CubeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,28 @@ public void onEntityChange(Broadcaster broadcaster, String entity, Event event,
}
}

/**
* List all cubes from cache. Note the metadata may be out of date
* @return
*/
public List<CubeInstance> listAllCubes() {
try (AutoLock lock = cubeMapLock.lockForRead()) {
return new ArrayList<CubeInstance>(cubeMap.values());
}
}

/**
* Reload the cubes from database and list all cubes
* @return
* @throws IOException
*/
public List<CubeInstance> reloadAndListAllCubes() throws IOException {
try (AutoLock lock = cubeMapLock.lockForWrite()) {
crud.reloadAll();
}
return listAllCubes();
}

public CubeInstance getCube(String cubeName) {
try (AutoLock lock = cubeMapLock.lockForRead()) {
return cubeMap.get(cubeName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public Map<String, Long> cleanup(boolean delete, int jobOutdatedDays) throws Exc

// exclude resources in use
Set<String> activeResources = Sets.newHashSet();
for (CubeInstance cube : cubeManager.listAllCubes()) {
for (CubeInstance cube : cubeManager.reloadAndListAllCubes()) {
activeResources.addAll(cube.getSnapshots().values());
for (CubeSegment segment : cube.getSegments()) {
activeResources.addAll(segment.getSnapshotPaths());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static List<String> cleanUnusedHBaseTables(HBaseAdmin hbaseAdmin, boolean delete
}

// remove every segment htable from drop list
for (CubeInstance cube : cubeMgr.listAllCubes()) {
for (CubeInstance cube : cubeMgr.reloadAndListAllCubes()) {
for (CubeSegment seg : cube.getSegments()) {
String tablename = seg.getStorageLocationIdentifier();
if (allTablesNeedToBeDropped.contains(tablename)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private void cleanUnusedHdfsFiles(FileSystem fs, UnusedHdfsFileCollector collect
}

// remove every segment working dir from deletion list
for (CubeInstance cube : cubeMgr.listAllCubes()) {
for (CubeInstance cube : cubeMgr.reloadAndListAllCubes()) {
for (CubeSegment seg : cube.getSegments()) {
String jobUuid = seg.getLastBuildJobID();
if (jobUuid != null && jobUuid.equals("") == false) {
Expand Down

0 comments on commit cfce8bb

Please sign in to comment.