Create or open a Log Structured Store, using the given path and LssSettings. Subsequent access to the store is through the ILogStructuredStore interface.
Note that the underlying file is opened with exclusive read/write access. It is not possible for another process (say) to open the same LSS file.
The EOpenMode parameter provides a number of options for opening and creating LSS stores. If errors occur due to a file's existence when it's not expected or absence when it's expected will result in a FileException being thrown.
If lssPath = "memfile", then the LSS will reside in memory.
createdNew returns a flag for whether a new store was created. If the openMode = OM_CREATE_ALWAYS, OM_DELETE_EXISTING or OM_CREATE_NEW any existing files will be deleted and createdNew will be true.
Note that if an existing store is opened and the existing segment size doesn't match the segment size specified in the settings, then the requested segment size will be ignored.
If an error occurs then throws a FileException (see FileException.h) or CorruptLSSException.
After using the store it must be closed by calling the Close() method. The interface pointer must not be deleted.
If deltasDirPath is not nullptr then it specifies the path to a directory in which to create delta files.
CreateOrOpenLSS() never returns nullptr
ILogStructuredStore* CreateOrOpenLSS(
ConstStringZ lssPath,
ConstStringZ deltasDirPath,
bool& createdNew,
EOpenMode openMode,
const LssSettings& settings);
The following code either opens an existing store or creates a new one if it doesn't exist. Then the store is closed. For simplicity error handling is not shown.
With the settings below, 4MB segments are used. This is the unit of reading and writing from disk. The segment size cannot be changed for existing stores.
There are 64 segments in the cache. This means the cache takes up 64 x 4MB = 256MB of system memory.
#include "Ceda/cxLss/ILogStructuredStore.h"
void OpenThenCloseLssExample()
{
const char* path = "myfile";
bool createdNew;
LssSettings settings;
settings.segmentSize = 4*1024*1024;
settings.maxNumSegmentsInCache = 64;
settings.flushTimeMilliSec = 2000;
ILogStructuredStore* lss = CreateOrOpenLSS(path, nullptr, createdNew, OM_OPEN_ALWAYS, settings);
if (createdNew)
{
std::cout << "A new store was created";
}
else
{
std::cout << "An existing store was opened";
}
lss->Close();
}