com.github.ltsopensource.kv.index.MemIndex Maven / Gradle / Ivy
package com.github.ltsopensource.kv.index;
import com.github.ltsopensource.kv.Entry;
import com.github.ltsopensource.kv.StoreConfig;
import com.github.ltsopensource.kv.cache.DataCache;
import com.github.ltsopensource.kv.data.DataBlockEngine;
import com.github.ltsopensource.kv.iterator.DBIterator;
import com.github.ltsopensource.kv.iterator.MemIteratorImpl;
import com.github.ltsopensource.kv.txlog.StoreTxLogPosition;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentSkipListMap;
/**
* @author Robert HG ([email protected]) on 12/16/15.
*/
public class MemIndex implements Index {
private StoreTxLogPosition lastTxLog;
private ConcurrentMap> indexMap;
private StoreConfig storeConfig;
private DataBlockEngine dataBlockEngine;
private DataCache dataCache;
public MemIndex(StoreConfig storeConfig, DataBlockEngine dataBlockEngine, DataCache dataCache) {
this.indexMap = new ConcurrentSkipListMap>();
this.storeConfig = storeConfig;
this.dataBlockEngine = dataBlockEngine;
this.dataCache = dataCache;
}
public IndexItem getIndexItem(K key) {
return indexMap.get(key);
}
@Override
public IndexItem removeIndexItem(StoreTxLogPosition txLogResult, K key) {
IndexItem value = indexMap.remove(key);
this.lastTxLog = txLogResult;
return value;
}
@Override
public void putIndexItem(StoreTxLogPosition txLogResult, K key, IndexItem indexItem) {
indexMap.put(key, indexItem);
this.lastTxLog = txLogResult;
}
@Override
public int size() {
return indexMap.size();
}
@Override
public boolean containsKey(K key) {
return indexMap.containsKey(key);
}
@Override
public DBIterator> iterator() {
return new MemIteratorImpl(this, dataBlockEngine, dataCache);
}
@Override
public StoreTxLogPosition lastTxLog() {
return lastTxLog;
}
void setLastTxLog(StoreTxLogPosition lastTxLog) {
this.lastTxLog = lastTxLog;
}
public ConcurrentMap> getIndexMap() {
return indexMap;
}
void setIndexMap(ConcurrentMap> indexMap) {
this.indexMap = indexMap;
}
}