Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Fix #741 Remove the usage of view
Browse files Browse the repository at this point in the history
  • Loading branch information
huafengw authored Jul 19, 2017
1 parent 83aeaa2 commit 6d481ca
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public HazelcastExecutorService(CmdletManager cmdletManager) {
}

private void initChannels() {
for (Member worker : HazelcastUtil.getWorkerMembers(this.instance)) {
for (Member worker : HazelcastUtil.getWorkerMembers(instance)) {
ITopic<Serializable> topic = instance.getTopic(WORKER_TOPIC_PREFIX + worker.getUuid());
this.masterToWorkers.put(worker.getUuid(), topic);
this.scheduledCmdlets.put(worker.getUuid(), new HashSet<Long>());
Expand All @@ -76,7 +76,7 @@ private void initChannels() {

public List<StandbyServerInfo> getStandbyServers() {
List<StandbyServerInfo> infos = new ArrayList<>();
for (Member worker : HazelcastUtil.getWorkerMembers(this.instance)) {
for (Member worker : HazelcastUtil.getWorkerMembers(instance)) {
infos.add(new StandbyServerInfo(worker.getUuid(), worker.getAddress().toString()));
}
return infos;
Expand All @@ -95,10 +95,10 @@ public boolean canAcceptMore() {
@Override
public void execute(LaunchCmdlet cmdlet) {
String[] members = masterToWorkers.keySet().toArray(new String[0]);
String memeber = members[random.nextInt() % members.length];
masterToWorkers.get(memeber).publish(cmdlet);
scheduledCmdlets.get(memeber).add(cmdlet.getCmdletId());
LOG.info(String.format("Executing cmdlet %s on worker %s", cmdlet.getCmdletId(), members));
String member = members[random.nextInt() % members.length];
masterToWorkers.get(member).publish(cmdlet);
scheduledCmdlets.get(member).add(cmdlet.getCmdletId());
LOG.info("Executing cmdlet {} on worker {}", cmdlet.getCmdletId(), members);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private List<String> getAccessCountTablesDuringLast(long lastInterval) {
+ accTables.size() + " tables:");
int idx = 1;
for (AccessCountTable t : accTables) {
LOG.debug(idx + ". " + (t.isView() ? " [VIEW] " : " ")
LOG.debug(idx + ". " + (t.isEphemeral() ? " [TABLE] " : " ")
+ t.getTableName() + " ");
}
}
Expand All @@ -220,8 +220,8 @@ private List<String> getAccessCountTablesDuringLast(long lastInterval) {

for (AccessCountTable t : accTables) {
tableNames.add(t.getTableName());
if (t.isView()) {
dynamicCleanups.push("DROP VIEW IF EXISTS " + t.getTableName() + ";");
if (t.isEphemeral()) {
dynamicCleanups.push("DROP TABLE IF EXISTS " + t.getTableName() + ";");
}
}
return tableNames;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ public synchronized List<FileAccessInfo> getHotFiles(
throw new MetaStoreException(e);
} finally {
for (AccessCountTable accessCountTable : tables) {
if (accessCountTable.isView()) {
this.dropView(accessCountTable.getTableName());
if (accessCountTable.isEphemeral()) {
this.dropTable(accessCountTable.getTableName());
}
}
}
Expand Down Expand Up @@ -470,11 +470,11 @@ public CachedFileStatus getCachedFileStatus(
}
}

public void createProportionView(AccessCountTable dest,
public void createProportionTable(AccessCountTable dest,
AccessCountTable source)
throws MetaStoreException {
try {
accessCountDao.createProportionView(dest, source);
accessCountDao.createProportionTable(dest, source);
} catch (Exception e) {
throw new MetaStoreException(e);
}
Expand All @@ -489,15 +489,6 @@ public void dropTable(String tableName) throws MetaStoreException {
}
}

public void dropView(String viewName) throws MetaStoreException {
try {
LOG.debug("Drop view = {}", viewName);
metaStoreHelper.dropView(viewName);
} catch (Exception e) {
throw new MetaStoreException(e);
}
}

public void execute(String sql) throws MetaStoreException {
try {
LOG.debug("Execute sql = {}", sql);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ private String getUnionStatement(List<AccessCountTable> tables) {
return union.toString();
}

public void createProportionView(AccessCountTable dest, AccessCountTable source)
public void createProportionTable(AccessCountTable dest, AccessCountTable source)
throws SQLException {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
double percentage =
((double) dest.getEndTime() - dest.getStartTime())
/ (source.getEndTime() - source.getStartTime());
String sql =
String.format(
"CREATE VIEW %s AS SELECT %s, ROUND(%s.%s * %s) AS %s FROM %s",
"CREATE TABLE %s AS SELECT %s, ROUND(%s.%s * %s) AS %s FROM %s",
dest.getTableName(),
AccessCountDao.FILE_FIELD,
source.getTableName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ public class AccessCountTable {
private final Long startTime;
private final Long endTime;
private final TimeGranularity granularity;
private final boolean isView;
private final boolean isEphemeral;

public AccessCountTable(Long startTime, Long endTime) {
this(startTime, endTime, false);
}

public AccessCountTable(Long startTime, Long endTime, boolean isView) {
this(getTableName(startTime, endTime, isView), startTime, endTime, isView);
public AccessCountTable(Long startTime, Long endTime, boolean isEphemeral) {
this(getTableName(startTime, endTime, isEphemeral), startTime, endTime, isEphemeral);
}

@VisibleForTesting
protected AccessCountTable(String name, Long startTime, Long endTime, boolean isView) {
protected AccessCountTable(String name, Long startTime, Long endTime, boolean isEphemeral) {
this.startTime = startTime;
this.endTime = endTime;
this.granularity = TimeUtils.getGranularity(endTime - startTime);
this.tableName = name;
this.isView = isView;
this.isEphemeral = isEphemeral;
}

public String getTableName() {
Expand Down Expand Up @@ -95,7 +95,7 @@ public String toString() {
this.tableName, this.startTime, this.endTime, this.granularity);
}

public boolean isView() {
return isView;
public boolean isEphemeral() {
return isEphemeral;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private static List<AccessCountTable> getTablesDuring(
// table that already exists, so this situation should be avoided.
if (!tableExists(tableDeques, startTime, table.getEndTime())) {
AccessCountTable splitTable = new AccessCountTable(startTime, table.getEndTime(), true);
metaStore.createProportionView(splitTable, table);
metaStore.createProportionTable(splitTable, table);
results.add(splitTable);
startTime = table.getEndTime();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public void testGetTablesCornerCase2() throws MetaStoreException {
Constants.ONE_MINUTE_IN_MILLIS);
Assert.assertTrue(result.size() == 3);
Assert.assertTrue(result.get(0).equals(firstFiveSeconds));
Assert.assertFalse(result.get(0).isView());
Assert.assertFalse(result.get(0).isEphemeral());
Assert.assertTrue(result.get(1).equals(secondFiveSeconds));
Assert.assertTrue(result.get(2).equals(thirdFiveSeconds));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void becomeActive() {
if (this.hazelcastWorker != null) {
this.hazelcastWorker.stop();
}
//SmartServer.main(args);
SmartServer.main(args);
}

public static void main(String[] args) {
Expand Down

0 comments on commit 6d481ca

Please sign in to comment.