Commit a3cc3fd2 authored by Georgios Bitzes's avatar Georgios Bitzes
Browse files

Ensure lease deadline stored in key descriptor is correctly updated

parent 81266396
Pipeline #425378 passed with stages
in 31 minutes and 21 seconds
......@@ -930,7 +930,7 @@ void StateMachine::WriteOperation::writeLocalityIndex(const std::string &field,
stagingArea.put(locator.toSlice(), hint);
}
rocksdb::Status StateMachine::WriteOperation::finalize(int64_t newsize) {
rocksdb::Status StateMachine::WriteOperation::finalize(int64_t newsize, bool forceUpdate) {
assertWritable();
if(newsize < 0) qdb_throw("invalid newsize: " << newsize);
......@@ -938,7 +938,7 @@ rocksdb::Status StateMachine::WriteOperation::finalize(int64_t newsize) {
if(newsize == 0) {
stagingArea.del(dlocator.toSlice());
}
else if(keyinfo.getSize() != newsize) {
else if(keyinfo.getSize() != newsize || forceUpdate) {
keyinfo.setSize(newsize);
stagingArea.put(dlocator.toSlice(), keyinfo.serialize());
}
......@@ -1139,7 +1139,7 @@ rocksdb::Status StateMachine::lease_acquire(StagingArea &stagingArea, const std:
// Update lease value.
operation.write(value);
acquired = true;
return operation.finalize(value.size());
return operation.finalize(value.size(), true);
}
rocksdb::Status StateMachine::lease_release(StagingArea &stagingArea, const std::string &key) {
......
......@@ -245,7 +245,7 @@ private:
bool deleteLocalityField(const std::string &hint, const std::string &field);
bool getAndDeleteLocalityIndex(const std::string &field, std::string &hint);
rocksdb::Status finalize(int64_t newsize);
rocksdb::Status finalize(int64_t newsize, bool forceUpdate = false);
KeyDescriptor& descriptor() {
return keyinfo;
......
......@@ -21,8 +21,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
************************************************************************/
#ifndef __QUARKDB_STAGING_AREA_H__
#define __QUARKDB_STAGING_AREA_H__
#ifndef QUARKDB_STAGING_AREA_H
#define QUARKDB_STAGING_AREA_H
#include <mutex>
#include "KeyDescriptor.hh"
......
......@@ -769,6 +769,17 @@ TEST_F(State_Machine, Leases) {
ASSERT_OK(stateMachine()->exists(keys.begin(), keys.end(), count) );
ASSERT_EQ(count, 0);
{
StagingArea stagingArea(*stateMachine());
DescriptorLocator locator("my-lease");
std::string tmp;
ASSERT_OK(stagingArea.get(locator.toSlice(), tmp));
KeyDescriptor descr(tmp);
ASSERT_EQ(descr.getSize(), 11u);
ASSERT_EQ(descr.getStartIndex(), 9u);
ASSERT_EQ(descr.getEndIndex(), 19u);
}
{
StagingArea stagingArea(*stateMachine());
ExpirationEventIterator iterator(stagingArea);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment