Issue Details (XML | Word | Printable)

Key: DERBY-132
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Mike Matrigali
Reporter: Mike Matrigali
Votes: 2
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Derby

in place table/index compress which returns space to OS

Created: 25/Jan/05 02:54 AM   Updated: 12/Jul/06 03:24 AM
Return to search
Component/s: Store
Affects Version/s: 10.1.1.0
Fix Version/s: 10.1.1.0

Time Tracking:
Not Specified

Resolution Date: 13/Jun/05 12:43 AM


 Description  « Hide
Each derby table or index is stored in a separate file. Space from
deleted rows is eventually reclaimed within the file as is used for
subsequent inserts into the same file. That space is not returned to
the OS unless the user calls the SYSCS_UTIL.SYSCS_COMPRESS_TABLE
system procedure. That procedure will return the unused space in
the tables and indexes to the OS. It gets an exclusive lock on the
table, copies all rows in the indexes and the base table into new
compressed files and delete the old files. Prior to jdk 1.4 this was
the only way to return space from a file to the OS.

In jdk 1.4 RandomAccessFile was enhanced to allow the truncation of a
file, which would return the space at the "end" of the file back to
the OS. In order to take advantage of this new feature a new
compress feature is needed in derby.

The assumption is that this work will be used in future work which will
automatically schedule this job and others in background, with no
interaction needed from the dba. The 1st phase of this work will
simply build a procedure that will do the work. The 2nd phase will
be to look into scheduling the procedure automatically as part of
the current background post commit processing. Longer term it would
be best if this fit into a new background task monitor, which could
schedule larger background tasks balanced against the other priorities
of the system. These tasks might include: this new online compress,
automatic statistics gathering, more proactive deleted row reclamation, ....

The proposed feature will reorganize base tables and indexes, moving
empty pages to the "end". It will release space back to the operating
system when it has created a chunk of empty pages at the end of the
file. It will be designed to run in background, and will lock resources
of the table for as short a time as possible so that it can iteratively
process the table.

To reclaim space in the heap, it will scan the heap in page reverse order.
It will get a short term table lock, process all the rows on a page, and
then commit that transaction releasing the lock. The commit will be
optimized like other internal transactions, and will not need to wait
for a synchonized write. Each row moved, will require all the index
entries for that row to also be updated. While doing the processing it
will also take care of processing committed deleted rows. When space
is free at the end of the table it will be freed back to the operating
system, using the RandomAccessFile.setLength() interface.

To reclaim space in the btree, data on pages will be moved rather than
rows. Data from pages at the end of the file will be moved to free
smaller numbered pages. Again short term table locks will be required,
and the operation will look similar to the current btree merge operations
already implemented. Again when a chunk of pages is free at the end of
the file, they will be returned to the OS using the same mechanism as
the heap.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
ASF #161468 Fri Apr 15 14:27:56 UTC 2005 mikem The following is the 1st phase of a checkin to address DERBY-132 - improvement
request to add an inplace compress.

This checkin addresses the issue in 3 parts:

1) Code has been added to purge committed rows from heap tables.
This code uses the same basic algorithm to identify and purge
committed deleted heap rows that currently exists. It scans the
entire heap table in the current thread processing all rows.

2) Code has been added to defragment remaining rows in the page, freeing
pages at the end of the table.
This code scans the table and moves rows from the end of the heap table
toward the front of the table. For every row moved all index entries
must be updated after the move. The allocation system is updated to
put new rows toward the front of the table. After it is finished there
will be a chunk of empty pages at the end of the file.

3) Code has been added to return the free space at the end of the table
back to the OS.
Finds the chunk of empty pages at the end of the file. Updates the
Allocation data structures to remove the chunk of pages at the end.
Calls the JVM to return the space at the end of the file back to the
OS.

In order to test all of these paths a new system procedure,
SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE has been added. Eventually
as a zero admin database the system should call this routine internally.
It allows each of the 3 above described phases to be called either
individually or in sequence.
Files Changed
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/conglomerate/Conglomerate.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseContainer.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/conglomerate/RowPosition.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BasePage.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/AllocPage.java
ADD /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineCompressTest_app.properties
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/Heap.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/sort/Scan.java
ADD /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapCompressScan.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/index/B2I.java
ADD /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/BaseTest.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/AllocExtent.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapScan.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapController.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/GroupFetchScanController.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/conglomerate/GenericScanController.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMTransaction.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
ADD /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/onlineCompressTable.sql
ADD /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineCompressTest.java
ADD /incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/db/OnlineCompress.java
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/copyfiles.ant
ADD /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BaseTest.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/conglomerate/OpenConglomerate.java
ADD /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineCompressTest_derby.properties
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/FileContainer.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/Page.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/InputStreamContainer.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/BTreeScan.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/BTreeController.java
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/copyfiles.ant
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/ContainerHandle.java
ADD /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/onlineCompressTable.out
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/TransactionController.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/StoredPage.java
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storetests.runall
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseContainerHandle.java

Repository Revision Date User Message
ASF #169492 Tue May 10 16:30:08 UTC 2005 mikem DERBY-132, inplace compress. Add btree truncate support. Enhance OnlineCompressTest.java test.
Files Changed
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/Heap.java
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineCompressTest.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/db/OnlineCompress.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/index/B2I.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/index/B2IRowLocking3.java
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BaseTest.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/index/B2IRowLocking1.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/index/B2IRowLockingRR.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/StoredPage.java
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/OnlineCompressTest.out
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineCompressTest_derby.properties
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/CheckpointOperation.java