예제 #1
0
void LogCache::DeleteOldRounds(uint64_t paxosID)
{
	Cursor			cursor;
	ByteArray<128>	buf;
	DynArray<128>	key;
	DynArray<128>	value;
	Transaction*	transaction;
	
	transaction = RLOG->GetTransaction();
	
	transaction->Begin();
	
	WriteRoundID(buf, paxosID);
	table->Iterate(transaction, cursor);
	if (!cursor.Start(buf))
	{
		cursor.Close();
		transaction->Rollback();
		return;
	}
		
	while (cursor.Prev(key, value))
	{
		if (key.length > sizeof("@@pround:") - 1 &&
		strncmp(key.buffer, "@@pround:", sizeof("@@pround:") - 1) == 0)
			cursor.Delete();
		else
			break;
	}
	
	cursor.Close();

	transaction->Commit();
}
예제 #2
0
void SingleKeyspaceDB::OnExpiryTimer()
{
	uint64_t	expiryTime;
	Cursor		cursor;
	ByteString	key;

	Log_Trace();
	
	table->Iterate(NULL, cursor);	
	kdata.Set("!!t:");
	if (!cursor.Start(kdata))
		ASSERT_FAIL();
	cursor.Close();
	
	if (kdata.length < 2)
		ASSERT_FAIL();
	
	if (kdata.buffer[0] != '!' || kdata.buffer[1] != '!')
		ASSERT_FAIL();

	ReadExpiryTime(kdata, expiryTime, key);
	table->Delete(NULL, kdata);
	table->Delete(NULL, key);

	WriteExpiryKey(kdata, key);
	table->Delete(NULL, kdata);
	
	Log_Trace("Expiring key: %.*s", key.length, key.buffer);

	InitExpiryTimer();
}
예제 #3
0
void SingleKeyspaceDB::InitExpiryTimer()
{
	uint64_t	expiryTime;
	Cursor		cursor;
	ByteString	key;

	Log_Trace();
	EventLoop::Remove(&expiryTimer);	
	
	table->Iterate(NULL, cursor);
	
	kdata.Set("!!t:");
	if (!cursor.Start(kdata))
		return;
	cursor.Close();
	
	if (kdata.length < 2)
		return;
	
	if (kdata.buffer[0] != '!' || kdata.buffer[1] != '!')
		return;

	ReadExpiryTime(kdata, expiryTime, key);

	expiryTimer.Set(expiryTime);
	EventLoop::Add(&expiryTimer);
}
예제 #4
0
void ReplicatedKeyspaceDB::InitExpiryTimer()
{
	uint64_t	expiryTime;
	Cursor		cursor;
	ByteString	key;

	Log_Trace();
	
	EventLoop::Remove(&expiryTimer);
	
	transaction = RLOG->GetTransaction();
	if (!transaction->IsActive())
		transaction->Begin();

	table->Iterate(transaction, cursor);
	
	kdata.Set("!!t:");
	if (!cursor.Start(kdata))
	{
		cursor.Close();
		return;
	}
	cursor.Close();
	
	if (kdata.length < 2)
		return;
	
	if (kdata.buffer[0] != '!' || kdata.buffer[1] != '!')
		return;

	ReadExpiryTime(kdata, expiryTime, key);
	Log_Trace("Setting expiry for %.*s at %" PRIu64 "", key.length, key.buffer, expiryTime);

	expiryTimer.Set(expiryTime);
	EventLoop::Add(&expiryTimer);
}
예제 #5
0
void ReplicatedKeyspaceDB::OnExpiryTimer()
{
	assert(RLOG->IsMaster());
	
	uint64_t	expiryTime;
	Cursor		cursor;
	ByteString	key;
	KeyspaceOp*	op;

	Log_Trace();
	
	if (expiryAdded)
		return;
	
	transaction = RLOG->GetTransaction();
	if (!transaction->IsActive())
		transaction->Begin();
	
	table->Iterate(transaction, cursor);	
	kdata.Set("!!t:");
	if (!cursor.Start(kdata))
		ASSERT_FAIL();
	cursor.Close();
	
	if (kdata.length < 2)
		ASSERT_FAIL();
	
	if (kdata.buffer[0] != '!' || kdata.buffer[1] != '!')
		ASSERT_FAIL();

	ReadExpiryTime(kdata, expiryTime, key);
	
	op = new KeyspaceOp;
	op->cmdID = 0;
	op->type = KeyspaceOp::EXPIRE;
	op->key.Allocate(key.length);
	op->key.Set(key);
	// expiryTime is set in Append()
	op->service = NULL;
	Add(op);
	Submit();
}