@Test public void testCannotTruncateColumnOnClose() throws Exception { int N = 100000; create(FF, PartitionBy.NONE, N); testTruncateOnClose(new TestFilesFacade() { long fd = -1; int count = 1; boolean ran = false; @Override public boolean isRestrictedFileSystem() { return false; } @Override public long openRW(LPSZ name) { if (Chars.endsWith(name, "price.d")) { return fd = super.openRW(name); } return super.openRW(name); } @Override public boolean truncate(long fd, long size) { if (this.fd == fd && count-- == 0) { ran = true; return false; } return super.truncate(fd, size); } @Override public boolean wasCalled() { return fd != -1 && ran; } }, N); }
public final void truncate() { if (size() == 0) { return; } writeTodo(TODO_TRUNCATE); for (int i = 0; i < columnCount; i++) { getPrimaryColumn(i).truncate(); AppendMemory mem = getSecondaryColumn(i); if (mem != null) { mem.truncate(); } } if (partitionBy != PartitionBy.NONE) { freeColumns(false); if (indexers != null) { for (int i = 0, n = indexers.size(); i < n; i++) { Misc.free(indexers.getQuick(i)); } } removePartitionDirectories(); rowFunction = openPartitionFunction; } prevMaxTimestamp = Long.MIN_VALUE; maxTimestamp = Long.MIN_VALUE; prevMinTimestamp = Long.MAX_VALUE; minTimestamp = Long.MAX_VALUE; txPrevTransientRowCount = 0; transientRowCount = 0; fixedRowCount = 0; txn++; txPartitionCount = 1; resetTxn(txMem, metadata.getSymbolMapCount(), txn, ++dataVersion); try { removeTodoFile(); } catch (CairoException err) { throwDistressException(err); } LOG.info().$("truncated [name=").$(name).$(']').$(); }
TableWriter implements Closeable { public final void truncate() { if (size() == 0) { return; } writeTodo(TODO_TRUNCATE); for (int i = 0; i < columnCount; i++) { getPrimaryColumn(i).truncate(); AppendMemory mem = getSecondaryColumn(i); if (mem != null) { mem.truncate(); } } if (partitionBy != PartitionBy.NONE) { freeColumns(false); if (indexers != null) { for (int i = 0, n = indexers.size(); i < n; i++) { Misc.free(indexers.getQuick(i)); } } removePartitionDirectories(); rowFunction = openPartitionFunction; } prevMaxTimestamp = Long.MIN_VALUE; maxTimestamp = Long.MIN_VALUE; prevMinTimestamp = Long.MAX_VALUE; minTimestamp = Long.MAX_VALUE; txPrevTransientRowCount = 0; transientRowCount = 0; fixedRowCount = 0; txn++; txPartitionCount = 1; resetTxn(txMem, metadata.getSymbolMapCount(), txn, ++dataVersion); try { removeTodoFile(); } catch (CairoException err) { throwDistressException(err); } LOG.info().$("truncated [name=").$(name).$(']').$(); } }
TableWriter implements Closeable { public final void truncate() { if (size() == 0) { return; } writeTodo(TODO_TRUNCATE); for (int i = 0; i < columnCount; i++) { getPrimaryColumn(i).truncate(); AppendMemory mem = getSecondaryColumn(i); if (mem != null) { mem.truncate(); } } if (partitionBy != PartitionBy.NONE) { freeColumns(false); if (indexers != null) { for (int i = 0, n = indexers.size(); i < n; i++) { Misc.free(indexers.getQuick(i)); } } removePartitionDirectories(); rowFunction = openPartitionFunction; } prevMaxTimestamp = Long.MIN_VALUE; maxTimestamp = Long.MIN_VALUE; prevMinTimestamp = Long.MAX_VALUE; minTimestamp = Long.MAX_VALUE; txPrevTransientRowCount = 0; transientRowCount = 0; fixedRowCount = 0; txn++; txPartitionCount = 1; resetTxn(txMem, metadata.getSymbolMapCount(), txn, ++dataVersion); try { removeTodoFile(); } catch (CairoException err) { throwDistressException(err); } LOG.info().$("truncated [name=").$(name).$(']').$(); } TableWriter(CairoConfiguration configuration, CharSequence name);  TableWriter(CairoConfiguration configuration, CharSequence name, MessageBus messageBus);  TableWriter(
            CairoConfiguration configuration,
            CharSequence name,
            @Nullable MessageBus messageBus,
            boolean lock,
            LifecycleManager lifecycleManager
    );  TableWriter(
            CairoConfiguration configuration,
            CharSequence name,
            @Nullable MessageBus messageBus,
            boolean lock,
            LifecycleManager lifecycleManager,
            CharSequence root
    ); }
TableWriter implements Closeable { public final void truncate() { if (size() == 0) { return; } writeTodo(TODO_TRUNCATE); for (int i = 0; i < columnCount; i++) { getPrimaryColumn(i).truncate(); AppendMemory mem = getSecondaryColumn(i); if (mem != null) { mem.truncate(); } } if (partitionBy != PartitionBy.NONE) { freeColumns(false); if (indexers != null) { for (int i = 0, n = indexers.size(); i < n; i++) { Misc.free(indexers.getQuick(i)); } } removePartitionDirectories(); rowFunction = openPartitionFunction; } prevMaxTimestamp = Long.MIN_VALUE; maxTimestamp = Long.MIN_VALUE; prevMinTimestamp = Long.MAX_VALUE; minTimestamp = Long.MAX_VALUE; txPrevTransientRowCount = 0; transientRowCount = 0; fixedRowCount = 0; txn++; txPartitionCount = 1; resetTxn(txMem, metadata.getSymbolMapCount(), txn, ++dataVersion); try { removeTodoFile(); } catch (CairoException err) { throwDistressException(err); } LOG.info().$("truncated [name=").$(name).$(']').$(); } TableWriter(CairoConfiguration configuration, CharSequence name);  TableWriter(CairoConfiguration configuration, CharSequence name, MessageBus messageBus);  TableWriter(
            CairoConfiguration configuration,
            CharSequence name,
            @Nullable MessageBus messageBus,
            boolean lock,
            LifecycleManager lifecycleManager
    );  TableWriter(
            CairoConfiguration configuration,
            CharSequence name,
            @Nullable MessageBus messageBus,
            boolean lock,
            LifecycleManager lifecycleManager,
            CharSequence root
    ); static TimestampFormat selectPartitionDirFmt(int partitionBy); void addColumn(CharSequence name, int type); void addColumn(
            CharSequence name,
            int type,
            int symbolCapacity,
            boolean symbolCacheFlag,
            boolean isIndexed,
            int indexValueBlockCapacity,
            boolean isSequential
    ); void addIndex(CharSequence columnName, int indexValueBlockSize); void changeCacheFlag(int columnIndex, boolean cache); @Override void close(); void commit(); void commit(int commitMode); int getColumnIndex(CharSequence name); long getMaxTimestamp(); RecordMetadata getMetadata(); CharSequence getName(); int getPartitionBy(); long getStructureVersion(); boolean inTransaction(); boolean isOpen(); Row newRow(long timestamp); Row newRow(); long partitionNameToTimestamp(CharSequence partitionName); void removeColumn(CharSequence name); void renameColumn(CharSequence currentName, CharSequence newName); boolean removePartition(long timestamp); void rollback(); void setLifecycleManager(LifecycleManager lifecycleManager); long size(); @Override String toString(); void transferLock(long lockFd); final void truncate(); void updateMetadataVersion(); void warmUp(); }
TableWriter implements Closeable { public final void truncate() { if (size() == 0) { return; } writeTodo(TODO_TRUNCATE); for (int i = 0; i < columnCount; i++) { getPrimaryColumn(i).truncate(); AppendMemory mem = getSecondaryColumn(i); if (mem != null) { mem.truncate(); } } if (partitionBy != PartitionBy.NONE) { freeColumns(false); if (indexers != null) { for (int i = 0, n = indexers.size(); i < n; i++) { Misc.free(indexers.getQuick(i)); } } removePartitionDirectories(); rowFunction = openPartitionFunction; } prevMaxTimestamp = Long.MIN_VALUE; maxTimestamp = Long.MIN_VALUE; prevMinTimestamp = Long.MAX_VALUE; minTimestamp = Long.MAX_VALUE; txPrevTransientRowCount = 0; transientRowCount = 0; fixedRowCount = 0; txn++; txPartitionCount = 1; resetTxn(txMem, metadata.getSymbolMapCount(), txn, ++dataVersion); try { removeTodoFile(); } catch (CairoException err) { throwDistressException(err); } LOG.info().$("truncated [name=").$(name).$(']').$(); } TableWriter(CairoConfiguration configuration, CharSequence name);  TableWriter(CairoConfiguration configuration, CharSequence name, MessageBus messageBus);  TableWriter(
            CairoConfiguration configuration,
            CharSequence name,
            @Nullable MessageBus messageBus,
            boolean lock,
            LifecycleManager lifecycleManager
    );  TableWriter(
            CairoConfiguration configuration,
            CharSequence name,
            @Nullable MessageBus messageBus,
            boolean lock,
            LifecycleManager lifecycleManager,
            CharSequence root
    ); static TimestampFormat selectPartitionDirFmt(int partitionBy); void addColumn(CharSequence name, int type); void addColumn(
            CharSequence name,
            int type,
            int symbolCapacity,
            boolean symbolCacheFlag,
            boolean isIndexed,
            int indexValueBlockCapacity,
            boolean isSequential
    ); void addIndex(CharSequence columnName, int indexValueBlockSize); void changeCacheFlag(int columnIndex, boolean cache); @Override void close(); void commit(); void commit(int commitMode); int getColumnIndex(CharSequence name); long getMaxTimestamp(); RecordMetadata getMetadata(); CharSequence getName(); int getPartitionBy(); long getStructureVersion(); boolean inTransaction(); boolean isOpen(); Row newRow(long timestamp); Row newRow(); long partitionNameToTimestamp(CharSequence partitionName); void removeColumn(CharSequence name); void renameColumn(CharSequence currentName, CharSequence newName); boolean removePartition(long timestamp); void rollback(); void setLifecycleManager(LifecycleManager lifecycleManager); long size(); @Override String toString(); void transferLock(long lockFd); final void truncate(); void updateMetadataVersion(); void warmUp();  }