Skip to content

Commit

Permalink
0001328: When there are lots of tables to synchronize it can slow dow…
Browse files Browse the repository at this point in the history
…n the save of a trigger or router link
  • Loading branch information
chenson42 committed Jul 17, 2013
1 parent c1389eb commit ea3383a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Expand Up @@ -158,7 +158,9 @@ public TriggerHistory getNewestTriggerHistoryForTrigger(String triggerId, String

public void syncTrigger(Trigger trigger, ITriggerCreationListener listener, boolean force);

public void syncTriggers(Table table, boolean genAlways);
public void syncTriggers(Table table, boolean genAlways);

public void dropTriggers(TriggerHistory history);

public void syncTriggers(boolean genAlways);

Expand Down
Expand Up @@ -496,9 +496,8 @@ protected void pushFilesToNode(NodeCommunication nodeCommunication, RemoteNodeSt
engine.getTransportManager(), engine.getAcknowledgeService());
status.updateOutgoingStatus(batches, batchAcks);
}
} catch (IOException e) {
} catch (Exception e) {
fireOffline(e, nodeCommunication.getNode(), status);
//throw new IoException(e);
} finally {
if (transport != null) {
transport.close();
Expand Down Expand Up @@ -647,10 +646,9 @@ protected void pullFilesFromNode(NodeCommunication nodeCommunication, RemoteNode
sendAck(nodeCommunication.getNode(), identity, security, batchesProcessed,
engine.getTransportManager());
}

} catch (IOException e) {
} catch (Exception e) {
fireOffline(e, nodeCommunication.getNode(), status);
//throw new IoException(e);
} finally {
if (transport != null) {
transport.close();
Expand Down
Expand Up @@ -100,6 +100,8 @@ public class TriggerRouterService extends AbstractService implements ITriggerRou
private List<String> extraConfigTables = new ArrayList<String>();

private Date lastUpdateTime;

private Object cacheLock = new Object();

/**
* Cache the history for performance. History never changes and does not
Expand Down Expand Up @@ -600,7 +602,7 @@ protected TriggerRoutersCache getTriggerRoutersCacheForCurrentNode(boolean refre
if (cache == null
|| refreshCache
|| System.currentTimeMillis() - this.triggerRouterCacheTime > triggerRouterCacheTimeoutInMs) {
synchronized (this) {
synchronized (cacheLock) {
this.triggerRouterCacheTime = System.currentTimeMillis();
Map<String, TriggerRoutersCache> newTriggerRouterCacheByNodeGroupId = new HashMap<String, TriggerRoutersCache>();
List<TriggerRouter> triggerRouters = getAllTriggerRoutersForCurrentNode(myNodeGroupId);
Expand Down Expand Up @@ -671,7 +673,7 @@ public Trigger getTriggerById(String triggerId, boolean refreshCache) {
Map<String, Trigger> cache = this.triggersCache;
if (cache == null || !cache.containsKey(triggerId) || refreshCache
|| (System.currentTimeMillis() - this.triggersCacheTime) > triggerCacheTimeoutInMs) {
synchronized (this) {
synchronized (cacheLock) {
this.triggersCacheTime = System.currentTimeMillis();
List<Trigger> triggers = new ArrayList<Trigger>(getTriggers());
triggers.addAll(buildTriggersForSymmetricTables(Version.version()));
Expand All @@ -695,7 +697,7 @@ public Router getRouterById(String routerId, boolean refreshCache) {
Map<String, Router> cache = this.routersCache;
if (cache == null || refreshCache
|| System.currentTimeMillis() - this.routersCacheTime > routerCacheTimeoutInMs) {
synchronized (this) {
synchronized (cacheLock) {
this.routersCacheTime = System.currentTimeMillis();
List<Router> routers = getRouters();
cache = new HashMap<String, Router>(routers.size());
Expand Down Expand Up @@ -1011,7 +1013,7 @@ public void syncTriggers(StringBuilder sqlBuffer, boolean force) {
}

public void clearCache() {
synchronized (this.getClass()) {
synchronized (cacheLock) {
this.triggerRouterCacheTime = 0;
this.routersCacheTime = 0;
this.triggersCacheTime = 0;
Expand Down Expand Up @@ -1080,6 +1082,10 @@ protected void inactivateTriggers(List<Trigger> triggersThatShouldBeActive,
}
}
}

public void dropTriggers(TriggerHistory history) {
dropTriggers(history, null);
}

protected void dropTriggers(TriggerHistory history, StringBuilder sqlBuffer) {

Expand Down

0 comments on commit ea3383a

Please sign in to comment.