Write operation fails with disk space available; after 'No space exception'

67 views
Skip to first unread message

Dharani Gajendiran

unread,
Jul 30, 2021, 4:59:08 AM7/30/21
to leveldb

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


Joe Steeve

unread,
Jul 30, 2021, 9:30:09 PM7/30/21
to lev...@googlegroups.com
On Fri, 2021-07-30 at 01:59 -0700, Dharani Gajendiran wrote:
> Is there a way to execute the program continuously without restarting it after
> the disk space available ?

You might have to re-open that DB again.

I doubt there is a way to clear the ENOSPC that is attached to that existing
file-descriptor.

--
Joe Steeve
HiPro IT Solutions Private Limited
http://www.hipro.co.in

signature.asc

Raistlin Majere

unread,
Mar 9, 2023, 4:21:55 PM3/9/23
to leveldb
the reason why error contiues showing up is leveldb has this background error feature to communicate IOError/Corruption between user requests and background compactions/flushes.

sadly there's no Resume method for users to carry on after fixing the problem, the only way to go is to reopen the db

Reply all
Reply to author
Forward
0 new messages