Search in sources :

Example 1 with EofMarkType

use of com.ctrip.xpipe.redis.core.protocal.protocal.EofMarkType in project x-pipe by ctripcorp.

the class DefaultRdbStoreEofMarkTest method beforeDefaultRdbStoreEofMarkTest.

@Before
public void beforeDefaultRdbStoreEofMarkTest() throws IOException {
    rdbFile = new File(String.format("%s/%s.rdb", getTestFileDir(), getTestName()));
    rdbStore = new DefaultRdbStore(rdbFile, 0, new EofMarkType(eofMark));
}
Also used : EofMarkType(com.ctrip.xpipe.redis.core.protocal.protocal.EofMarkType) File(java.io.File) Before(org.junit.Before)

Example 2 with EofMarkType

use of com.ctrip.xpipe.redis.core.protocal.protocal.EofMarkType in project x-pipe by ctripcorp.

the class DefaultRdbStore method createControllableFile.

private ControllableFile createControllableFile() throws IOException {
    if (eofType instanceof LenEofType) {
        return new DefaultControllableFile(file);
    } else if (eofType instanceof EofMarkType) {
        return new SizeControllableFile(file, new FileSize() {

            @Override
            public long getSize(LongSupplier realSizeProvider) {
                long realSize = 0;
                synchronized (truncateLock) {
                    // truncate may make size wrong
                    realSize = realSizeProvider.getAsLong();
                }
                if (status.get() == Status.Writing) {
                    long ret = realSize - ((EofMarkType) eofType).getTag().length();
                    logger.debug("[getSize][writing]{}, {}", DefaultRdbStore.this, ret);
                    return ret < 0 ? 0 : ret;
                }
                return realSize;
            }
        });
    } else {
        throw new IllegalStateException("unknown eoftype:" + eofType.getClass() + "," + eofType);
    }
}
Also used : DefaultControllableFile(com.ctrip.xpipe.utils.DefaultControllableFile) SizeControllableFile(com.ctrip.xpipe.utils.SizeControllableFile) EofMarkType(com.ctrip.xpipe.redis.core.protocal.protocal.EofMarkType) LenEofType(com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType) LongSupplier(java.util.function.LongSupplier) FileSize(com.ctrip.xpipe.api.utils.FileSize)

Aggregations

EofMarkType (com.ctrip.xpipe.redis.core.protocal.protocal.EofMarkType)2 FileSize (com.ctrip.xpipe.api.utils.FileSize)1 LenEofType (com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType)1 DefaultControllableFile (com.ctrip.xpipe.utils.DefaultControllableFile)1 SizeControllableFile (com.ctrip.xpipe.utils.SizeControllableFile)1 File (java.io.File)1 LongSupplier (java.util.function.LongSupplier)1 Before (org.junit.Before)1