ai.grakn.kb.log.CommitLog Maven / Gradle / Ivy
/*
* GRAKN.AI - THE KNOWLEDGE GRAPH
* Copyright (C) 2018 Grakn Labs Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package ai.grakn.kb.log;
import ai.grakn.Keyspace;
import ai.grakn.concept.ConceptId;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
*
* Stores the commit log of a {@link ai.grakn.GraknTx}.
*
*
*
* Stores the commit log of a {@link ai.grakn.GraknTx} which is uploaded to the server when the {@link ai.grakn.GraknSession} is closed.
* The commit log is also uploaded periodically to make sure that if a failure occurs the counts are still roughly maintained.
*
*
* @author Filipe Peliz Pinto Teixeira
*/
@AutoValue
public abstract class CommitLog {
@JsonProperty
public abstract Keyspace keyspace();
@JsonProperty("instance-count")
public abstract Map instanceCount();
@JsonProperty("new-attributes")
public abstract Map> attributes();
@JsonCreator
public static CommitLog create(
@JsonProperty("keyspace") Keyspace keyspace,
@JsonProperty("instance-count") Map instanceCount,
@JsonProperty("new-attributes") Map> newAttributes
){
return new AutoValue_CommitLog(keyspace, instanceCount, newAttributes);
}
/**
* Creates a {@link CommitLog} which is safe to be mutated by multiple transactions
* @return a thread safe {@link CommitLog}
*/
public static CommitLog createThreadSafe(Keyspace keyspace){
return create(keyspace, new ConcurrentHashMap<>(), new ConcurrentHashMap<>());
}
/**
* Creates a {@link CommitLog} which should only be used by a single transaction.
* @return a simple {@link CommitLog}
*/
public static CommitLog createDefault(Keyspace keyspace){
return create(keyspace, new HashMap<>(), new HashMap<>());
}
public void clear(){
instanceCount().clear();
attributes().clear();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy