public class BigArrayImpl extends Object implements IBigArray
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_DATA_PAGE_SIZE |
static int |
MINIMUM_DATA_PAGE_SIZE |
| Constructor and Description |
|---|
BigArrayImpl(String arrayDir,
String arrayName)
A big array implementation supporting sequential write and random read,
use default back data file size per page, see
DEFAULT_DATA_PAGE_SIZE. |
BigArrayImpl(String arrayDir,
String arrayName,
int pageSize)
A big array implementation supporting sequential write and random read.
|
| Modifier and Type | Method and Description |
|---|---|
long |
append(byte[] data)
Append the data into the head of the array
|
void |
close() |
long |
findClosestIndex(long timestamp)
Find an index closest to the specific timestamp when the corresponding item was appended
|
void |
flush()
Force to persist newly appended data,
normally, you don't need to flush explicitly since:
1.) BigArray will automatically flush a cached page when it is replaced out,
2.) BigArray uses memory mapped file technology internally, and the OS will flush the changes even your process crashes,
call this periodically only if you need transactional reliability and you are aware of the cost to performance.
|
byte[] |
get(long index)
Get the data at specific index
|
String |
getArrayDirectory() |
long |
getBackFileSize()
Get total size of back files(index and data files) of the big array
|
int |
getDataPageSize()
Get the back data file size per page.
|
long |
getHeadIndex()
The head of the array.
|
int |
getItemLength(long index)
Get the data item length at specific index
|
long |
getTailIndex()
The tail of the array.
|
long |
getTimestamp(long index)
Get the timestamp of data at specific index,
this is the timestamp when the data was appended.
|
boolean |
isEmpty()
Check if the array is empty or not
|
boolean |
isFull()
Check if the ring space of java long type has all been used up.
|
void |
limitBackFileSize(long sizeLimit)
limit the back file size, truncate back file and advance array tail index accordingly,
Note, this is a best effort call, exact size limit can't be guaranteed
|
void |
removeAll()
Remove all data in this array, this will empty the array and delete all back page files.
|
void |
removeBefore(long timestamp)
Remove all data before specific timestamp, this will advance the array tail and delete back page files
accordingly.
|
void |
removeBeforeIndex(long index)
Remove all data before specific index, this will advance the array tail to index and
delete back page files before index.
|
void |
setClock(Clock clock)
Used for changing the clock for unit tests
|
long |
size()
The total number of items has been appended into the array
|
public static final int DEFAULT_DATA_PAGE_SIZE
public static final int MINIMUM_DATA_PAGE_SIZE
public BigArrayImpl(String arrayDir, String arrayName) throws IOException
DEFAULT_DATA_PAGE_SIZE.arrayDir - directory for array data storearrayName - the name of the array, will be appended as last part of the array directoryIOException - exception throws during array initializationpublic BigArrayImpl(String arrayDir, String arrayName, int pageSize) throws IOException
arrayDir - directory for array data storearrayName - the name of the array, will be appended as last part of the array directorypageSize - the back data file size per page in bytes, see minimum allowed MINIMUM_DATA_PAGE_SIZE.IOException - exception throws during array initializationpublic void setClock(Clock clock)
clock - Clock instance to usepublic String getArrayDirectory()
public void removeAll()
throws IOException
IBigArrayremoveAll in interface IBigArrayIOException - exception thrown if IO error occurs durring remove allpublic void removeBeforeIndex(long index)
throws IOException
IBigArrayremoveBeforeIndex in interface IBigArrayindex - an indexIOException - exception thrown if there was any IO error during the removal operationpublic void removeBefore(long timestamp)
throws IOException
IBigArrayremoveBefore in interface IBigArraytimestamp - a timestampIOException - exception thrown if there was any IO error during the removal operationpublic long append(byte[] data)
throws IOException
append in interface IBigArraydata - binary data to appendIOException - if there is any IO errorpublic void flush()
IBigArraypublic byte[] get(long index)
throws IOException
IBigArrayget in interface IBigArrayindex - valid data indexIOException - if there is any IO errorpublic long getTimestamp(long index)
throws IOException
IBigArraygetTimestamp in interface IBigArrayindex - valid data indexIOException - if there is any IO errorpublic long size()
IBigArraypublic long getHeadIndex()
IBigArraygetHeadIndex in interface IBigArraypublic long getTailIndex()
IBigArraygetTailIndex in interface IBigArraypublic boolean isEmpty()
IBigArraypublic boolean isFull()
IBigArraypublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic int getDataPageSize()
IBigArraygetDataPageSize in interface IBigArraypublic long findClosestIndex(long timestamp)
throws IOException
IBigArrayfindClosestIndex in interface IBigArraytimestamp - when the corresponding item was appendedIOException - exception thrown if there was any IO error during the getClosestIndex operationpublic long getBackFileSize()
throws IOException
IBigArraygetBackFileSize in interface IBigArrayIOException - exception thrown if there was any IO error during the getBackFileSize operationpublic void limitBackFileSize(long sizeLimit)
throws IOException
IBigArraylimitBackFileSize in interface IBigArraysizeLimit - the size to limitIOException - exception thrown if there was any IO error during the limitBackFileSize operationpublic int getItemLength(long index)
throws IOException
IBigArraygetItemLength in interface IBigArrayindex - valid data indexIOException - if there is any IO errorCopyright © 2022. All rights reserved.