Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor TTL handling in diskstorage
This commit is a wash in terms of simplification: 169 lines removed, but still 165 added. Might not be worth it. It's also only barely tested (ran titan-cassandra but not titan-hbase tests). For #971
- Loading branch information
Showing
15 changed files
with
165 additions
and
169 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
23 changes: 0 additions & 23 deletions
23
...in/java/com/thinkaurelius/titan/diskstorage/keycolumnvalue/CustomizeStoreKCVSManager.java
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
89 changes: 89 additions & 0 deletions
89
.../src/main/java/com/thinkaurelius/titan/diskstorage/keycolumnvalue/ttl/TTLKCVSManager.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.thinkaurelius.titan.diskstorage.keycolumnvalue.ttl; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.Maps; | ||
import com.thinkaurelius.titan.diskstorage.BackendException; | ||
import com.thinkaurelius.titan.diskstorage.Entry; | ||
import com.thinkaurelius.titan.diskstorage.EntryMetaData; | ||
import com.thinkaurelius.titan.diskstorage.MetaAnnotatable; | ||
import com.thinkaurelius.titan.diskstorage.StaticBuffer; | ||
import com.thinkaurelius.titan.diskstorage.configuration.Configuration; | ||
import com.thinkaurelius.titan.diskstorage.keycolumnvalue.KCVMutation; | ||
import com.thinkaurelius.titan.diskstorage.keycolumnvalue.KCVSManagerProxy; | ||
import com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyColumnValueStore; | ||
import com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyColumnValueStoreManager; | ||
import com.thinkaurelius.titan.diskstorage.keycolumnvalue.StandardStoreFeatures; | ||
import com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreFeatures; | ||
import com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
import static com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration.STORE_TTL_SECONDS; | ||
|
||
/** | ||
* @author Matthias Broecheler (me@matthiasb.com) | ||
*/ | ||
public class TTLKCVSManager extends KCVSManagerProxy { | ||
|
||
private final StoreFeatures features; | ||
private final Map<String, Integer> ttlEnabledStores = Maps.newConcurrentMap(); | ||
|
||
public TTLKCVSManager(KeyColumnValueStoreManager manager) { | ||
super(manager); | ||
Preconditions.checkArgument(supportsStoreTTL(manager), | ||
"Wrapped store must support cell or store level TTL: %s", manager); | ||
Preconditions.checkArgument(manager.getFeatures().hasCellTTL()); | ||
this.features = new StandardStoreFeatures.Builder(manager.getFeatures()).storeTTL(true).build(); | ||
} | ||
|
||
public static boolean supportsStoreTTL(KeyColumnValueStoreManager manager) { | ||
return supportsStoreTTL(manager.getFeatures()); | ||
} | ||
|
||
public static boolean supportsStoreTTL(StoreFeatures features) { | ||
return features.hasCellTTL() || features.hasStoreTTL(); | ||
} | ||
|
||
@Override | ||
public StoreFeatures getFeatures() { | ||
return features; | ||
} | ||
|
||
@Override | ||
public KeyColumnValueStore openDatabase(String name, Configuration options) throws BackendException { | ||
KeyColumnValueStore store = manager.openDatabase(name); | ||
int storeTTL = -1; | ||
if (options.has(STORE_TTL_SECONDS)) { | ||
storeTTL = options.get(STORE_TTL_SECONDS); | ||
} | ||
Preconditions.checkArgument(storeTTL>0,"TTL must be positive: %s", storeTTL); | ||
ttlEnabledStores.put(name, storeTTL); | ||
return new TTLKCVS(store, storeTTL); | ||
} | ||
|
||
@Override | ||
public void mutateMany(Map<String, Map<StaticBuffer, KCVMutation>> mutations, StoreTransaction txh) throws BackendException { | ||
if (!manager.getFeatures().hasStoreTTL()) { | ||
assert manager.getFeatures().hasCellTTL(); | ||
for (Map.Entry<String,Map<StaticBuffer, KCVMutation>> sentry : mutations.entrySet()) { | ||
Integer ttl = ttlEnabledStores.get(sentry.getKey()); | ||
if (null != ttl && 0 < ttl) { | ||
for (KCVMutation mut : sentry.getValue().values()) { | ||
if (mut.hasAdditions()) applyTTL(mut.getAdditions(), ttl); | ||
} | ||
} | ||
} | ||
} | ||
manager.mutateMany(mutations,txh); | ||
} | ||
|
||
public static void applyTTL(Collection<Entry> additions, int ttl) { | ||
for (Entry entry : additions) { | ||
assert entry instanceof MetaAnnotatable; | ||
((MetaAnnotatable)entry).setMetaData(EntryMetaData.TTL,ttl); | ||
} | ||
} | ||
|
||
|
||
} |
107 changes: 0 additions & 107 deletions
107
.../src/main/java/com/thinkaurelius/titan/diskstorage/keycolumnvalue/ttl/TTLKVCSManager.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.