Created
November 2, 2016 16:14
-
-
Save jsanda/f9967c1b8d506fb0807a8835a745810d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void initSchema() { | |
doWithLock("cassalog", () -> { | |
SchemaService schemaService = new SchemaService(); | |
schemaService.run(session, keyspace, Boolean.parseBoolean(resetDb)); | |
session.execute("USE " + keyspace); | |
}); | |
} | |
private void doWithLock(String key, Runnable runnable) { | |
AdvancedCache<String, String> cache = locksCache.getAdvancedCache(); | |
DistributedLock schemaLock = new DistributedLock(cache); | |
try { | |
schemaLock.lock(); | |
while (!schemaLock.isLocked()) { | |
log.info("Failed to acquire schema lock. Trying again in 10 seconds."); | |
Thread.sleep(10000); | |
schemaLock.lock(); | |
} | |
runnable.run(); | |
} catch (Throwable t) { | |
throw new RuntimeException(t); | |
} finally { | |
schemaLock.release(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment