We have the following code snippet, where the program continuously inserts the key-value pair and after every insert, it tries to read the same key and prints the key value as ‘ok’.
When there is no disk space the put method throws "IO error: No space left on device". After making the space available also, the error continues. We must restart the program and the write operation happens.
Is there a way to execute the program continuously without restarting it after the disk space available ?
// Set up database connection information and open database
leveldb::DB* db;
leveldb::Options options;
options.create_if_missing = true;
leveldb::Status dbStatus = leveldb::DB::Open(options, "./testdb", &db);
if (false == dbStatus.ok())
{
cerr << "Unable to open/create test database 'testdb'" << endl;
cerr << dbStatus.ToString() << endl;
return -1;
}
leveldb::WriteOptions writeOptions;
leveldb::ReadOptions readOptions;
for (unsigned int i = 0; i < 3000000000; ++i)
{
ostringstream keyStream;
ostringstream valueStream;
std::string value;
keyStream << "Key" << i;
valueStream << "1234567890123456789112345678921234567893123456789412345678951234567896123456789712345678981234567899" << i;
leveldb::Status putStatus = db->Put (writeOptions, keyStream.str(), valueStream.str());
leveldb::Status getStatus = db->Get (readOptions, keyStream.str(), &value);
if (getStatus.ok())
{
cout << keyStream.str() << " - ok" << endl;
}
else
{
cerr << "Put Status: " << putStatus.ToString() << endl;
cerr << "Get Status: " << getStatus.ToString() << keyStream.str() << endl;
}
}// Output of this snippet
Key2337618 – ok
Key2337618 – ok
Put Status: IO error: ./testdb/000513.log: No space left on device
Get Status: NotFound: Key2337619
Put Status: IO error: ./testdb/000513.log: No space left on device
Get Status: NotFound: Key2337620