修改部分类型,修改主索引文件,命名为块索引文件
This commit is contained in:
parent
f2bdef7fa7
commit
8d63c0e5f2
|
|
@ -1,14 +1,14 @@
|
|||
package com.a.eye.skywalking.storage.index;
|
||||
package com.a.eye.skywalking.storage.block.index;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/11/2.
|
||||
*/
|
||||
public class DataFileFinder {
|
||||
public class BlockFinder {
|
||||
|
||||
private IndexL1Cache l1Cache;
|
||||
private IndexL2Cache l2Cache;
|
||||
private L1Cache l1Cache;
|
||||
private L2Cache l2Cache;
|
||||
|
||||
public DataFileFinder(IndexL1Cache l1Cache, IndexL2Cache l2Cache) {
|
||||
public BlockFinder(L1Cache l1Cache, L2Cache l2Cache) {
|
||||
this.l1Cache = l1Cache;
|
||||
this.l2Cache = l2Cache;
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package com.a.eye.skywalking.storage.block.index;
|
||||
|
||||
|
||||
public class BlockIndexEngine {
|
||||
|
||||
private static L1Cache l1Cache;
|
||||
private static L2Cache l2Cache;
|
||||
|
||||
|
||||
public static void start(){
|
||||
l1Cache = new L1Cache();
|
||||
l2Cache = new L2Cache();
|
||||
newUpdator().init();
|
||||
}
|
||||
|
||||
public static BlockFinder newFinder() {
|
||||
return new BlockFinder(l1Cache, l2Cache);
|
||||
}
|
||||
|
||||
|
||||
public static BlockIndexUpdator newUpdator() {
|
||||
return new BlockIndexUpdator(l1Cache, l2Cache);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package com.a.eye.skywalking.storage.index;
|
||||
package com.a.eye.skywalking.storage.block.index;
|
||||
|
||||
import com.a.eye.skywalking.storage.index.exception.DataFileIndexSaveFailedException;
|
||||
import com.a.eye.skywalking.storage.block.index.exception.BlockIndexPersistenceFailedException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
|
@ -12,13 +12,13 @@ import java.util.List;
|
|||
import static com.a.eye.skywalking.storage.config.Config.DataFileIndex.DATA_FILE_INDEX_FILE_NAME;
|
||||
import static com.a.eye.skywalking.storage.config.Config.DataFileIndex.STORAGE_BASE_PATH;
|
||||
|
||||
public class DataFileIndexUpdator {
|
||||
public class BlockIndexUpdator {
|
||||
|
||||
private static Logger logger = LogManager.getLogger(DataFileIndexUpdator.class);
|
||||
private IndexL1Cache l1Cache;
|
||||
private IndexL2Cache l2Cache;
|
||||
private static Logger logger = LogManager.getLogger(BlockIndexUpdator.class);
|
||||
private L1Cache l1Cache;
|
||||
private L2Cache l2Cache;
|
||||
|
||||
public DataFileIndexUpdator(IndexL1Cache l1Cache, IndexL2Cache l2Cache) {
|
||||
public BlockIndexUpdator(L1Cache l1Cache, L2Cache l2Cache) {
|
||||
this.l1Cache = l1Cache;
|
||||
this.l2Cache = l2Cache;
|
||||
}
|
||||
|
|
@ -34,12 +34,12 @@ public class DataFileIndexUpdator {
|
|||
}
|
||||
|
||||
private void updateCache(long timestamp) {
|
||||
l1Cache.update(timestamp);
|
||||
l2Cache.update(timestamp);
|
||||
l1Cache.add2Rebuild(timestamp);
|
||||
l2Cache.add2Rebuild(timestamp);
|
||||
}
|
||||
|
||||
|
||||
private void updateFile(long timestamp) throws DataFileIndexSaveFailedException {
|
||||
private void updateFile(long timestamp) throws BlockIndexPersistenceFailedException {
|
||||
BufferedWriter writer = null;
|
||||
try {
|
||||
writer = new BufferedWriter(new FileWriter(new File(STORAGE_BASE_PATH, DATA_FILE_INDEX_FILE_NAME)));
|
||||
|
|
@ -47,7 +47,7 @@ public class DataFileIndexUpdator {
|
|||
writer.newLine();
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
throw new DataFileIndexSaveFailedException("Failed to save index[" + timestamp + "]", e);
|
||||
throw new BlockIndexPersistenceFailedException("Failed to save index[" + timestamp + "]", e);
|
||||
} finally {
|
||||
if (writer != null) {
|
||||
try {
|
||||
|
|
@ -83,7 +83,7 @@ public class DataFileIndexUpdator {
|
|||
}
|
||||
|
||||
Collections.reverse(indexData);
|
||||
l1Cache.initData(indexData);
|
||||
l2Cache.initData(indexData);
|
||||
l1Cache.init(indexData);
|
||||
l2Cache.init(indexData);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.a.eye.skywalking.storage.index;
|
||||
package com.a.eye.skywalking.storage.block.index;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
|
@ -10,16 +10,18 @@ import java.util.concurrent.locks.ReadWriteLock;
|
|||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
/**
|
||||
* 块索引的一级缓存
|
||||
*
|
||||
* Created by xin on 2016/11/2.
|
||||
*/
|
||||
public class IndexL1Cache {
|
||||
public class L1Cache {
|
||||
|
||||
private static final int MAX_DATA_KEEP_SIZE = 30;
|
||||
private static Logger logger = LogManager.getLogger(IndexL1Cache.class);
|
||||
private static Logger logger = LogManager.getLogger(L1Cache.class);
|
||||
private TreeSet<Long> cacheData = new TreeSet<Long>();
|
||||
private final ReadWriteLock updateLock = new ReentrantReadWriteLock();
|
||||
|
||||
void initData(List<Long> data) {
|
||||
void init(List<Long> data) {
|
||||
for (int i = 0; i < MAX_DATA_KEEP_SIZE; i++) {
|
||||
this.cacheData.add(data.get(i));
|
||||
}
|
||||
|
|
@ -35,7 +37,7 @@ public class IndexL1Cache {
|
|||
}
|
||||
}
|
||||
|
||||
public void update(long timestamp) {
|
||||
public void add2Rebuild(long timestamp) {
|
||||
TreeSet<Long> newCacheData = new TreeSet<>(cacheData);
|
||||
newCacheData.add(timestamp);
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.a.eye.skywalking.storage.index;
|
||||
package com.a.eye.skywalking.storage.block.index;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
|
|
@ -6,12 +6,15 @@ import java.util.concurrent.locks.Lock;
|
|||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
public class IndexL2Cache {
|
||||
/**
|
||||
* 块索引的二级缓存
|
||||
*/
|
||||
public class L2Cache {
|
||||
|
||||
private TreeSet<Long> cacheData = new TreeSet<Long>();
|
||||
private ReadWriteLock updateLock = new ReentrantReadWriteLock();
|
||||
|
||||
void initData(List<Long> data) {
|
||||
void init(List<Long> data) {
|
||||
this.cacheData.addAll(cacheData);
|
||||
}
|
||||
|
||||
|
|
@ -25,7 +28,7 @@ public class IndexL2Cache {
|
|||
}
|
||||
}
|
||||
|
||||
public void update(long timestamp) {
|
||||
public void add2Rebuild(long timestamp) {
|
||||
TreeSet<Long> newCacheData = new TreeSet<>(cacheData);
|
||||
newCacheData.add(timestamp);
|
||||
Lock lock = updateLock.writeLock();
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package com.a.eye.skywalking.storage.block.index.exception;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/11/2.
|
||||
*/
|
||||
public class BlockIndexPersistenceFailedException extends Exception {
|
||||
public BlockIndexPersistenceFailedException(String message, Exception e) {
|
||||
super(message, e);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
package com.a.eye.skywalking.storage.index;
|
||||
|
||||
|
||||
public class DataFileIndexEngine {
|
||||
|
||||
private static IndexL1Cache l1Cache;
|
||||
private static IndexL2Cache l2Cache;
|
||||
|
||||
|
||||
public static void start(){
|
||||
l1Cache = new IndexL1Cache();
|
||||
l2Cache = new IndexL2Cache();
|
||||
newUpdator().init();
|
||||
}
|
||||
|
||||
public static DataFileFinder newFinder() {
|
||||
return new DataFileFinder(l1Cache, l2Cache);
|
||||
}
|
||||
|
||||
|
||||
public static DataFileIndexUpdator newUpdator() {
|
||||
return new DataFileIndexUpdator(l1Cache, l2Cache);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
package com.a.eye.skywalking.storage.index.exception;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/11/2.
|
||||
*/
|
||||
public class DataFileIndexSaveFailedException extends Exception {
|
||||
public DataFileIndexSaveFailedException(String message, Exception e) {
|
||||
super(message, e);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.a.eye.skywalking.storage.index;
|
||||
package com.a.eye.skywalking.storage.block.index;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/10/31.
|
||||
Loading…
Reference in New Issue