-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Scan Iterator over Hybrid Log This iterator takes in a begin and end address. Calling getNext() returns a pointer to the next record in the range. If the end has been reached, then nullptr is returned. If we need to scan over disk, then the iterator can optionally scan extra pages and buffer them internally. * Upsert and Delete contexts for Log Compaction The Log Compaction algorithm requires that we a) Collect records into a temporary faster instance b) Delete dead records from this instance c) Upsert live records at the tail of the log To perform the above three we need an Upsert and Delete context. * Compaction for HybridLog Implements a 3 phased approach similar to the C# version. Phase 1: Collects records from the region to be compacted into a mini-FASTER instance. Phase 2: Scans records in FASTER's log upto the safe read-only offset, deleting them from the mini-FASTER instance. Phase 3: Inserts records from the mini-FASTER into the hybrid log as long as they don't exist in it's mutable region. * Unit test for in-memory scan iterator * Read correct page from disk when scanning * Simple unit test for compaction * Fix Windows compile error. * Fix copyright on compact.h Co-authored-by: Badrish Chandramouli <badrishc@microsoft.com>
- Loading branch information
1 parent
7122495
commit c98de54
Showing
6 changed files
with
854 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
#pragma once | ||
|
||
#include "core/async.h" | ||
|
||
#include "record.h" | ||
|
||
namespace FASTER { | ||
namespace core { | ||
|
||
/// Upsert context used by FASTER's compaction algorithm. | ||
/// | ||
/// The following are template arguments. | ||
/// K: The type on the key of each record. | ||
/// V: The type on the value stored inside FASTER. | ||
template <class K, class V> | ||
class CompactionUpsert : public IAsyncContext { | ||
public: | ||
// Typedefs on the key and value required internally by FASTER. | ||
typedef K key_t; | ||
typedef V value_t; | ||
|
||
// Type signature on the record. Required by the constructor. | ||
typedef Record<K, V> record_t; | ||
|
||
/// Constructs and returns a context given a pointer to a record. | ||
CompactionUpsert(record_t* record) | ||
: key_(record->key()) | ||
, value_(record->value()) | ||
{} | ||
|
||
/// Copy constructor. Required for when an Upsert operation goes async | ||
/// inside FASTER. | ||
CompactionUpsert(const CompactionUpsert& from) | ||
: key_(from.key_) | ||
, value_(from.value_) | ||
{} | ||
|
||
/// Accessor for the key. Invoked from within FASTER. | ||
inline const K& key() const { | ||
return key_; | ||
} | ||
|
||
/// Returns the size of the value. Invoked from within FASTER when creating | ||
/// a new key-value pair (because the key did not map to a value to begin | ||
/// with). | ||
inline static constexpr uint32_t value_size() { | ||
return V::size(); | ||
} | ||
|
||
/// Stores this context's value into a passed in reference. This is | ||
/// typically invoked from within FASTER when a new record corresponding | ||
/// to the key-value pair is created at the tail of the hybrid log. | ||
inline void Put(V& val) { | ||
new(&val) V(value_); | ||
} | ||
|
||
/// Atomically stores this context's value into a passed in reference. This | ||
/// is typically invoked from within FASTER when performing an Upsert on a | ||
/// key-value pair in the HybridLog's mutable region. | ||
inline bool PutAtomic(V& val) { | ||
new(&val) V(value_); | ||
return true; | ||
} | ||
|
||
protected: | ||
/// Copies this context into a passed-in pointer if the operation goes | ||
/// asynchronous inside FASTER. | ||
Status DeepCopy_Internal(IAsyncContext*& context_copy) { | ||
return IAsyncContext::DeepCopy_Internal(*this, context_copy); | ||
} | ||
|
||
private: | ||
/// The key the upsert must be performed against. | ||
K key_; | ||
|
||
/// The value that the key should map to after the Upsert operation. | ||
V value_; | ||
}; | ||
|
||
/// Delete context used by FASTER's compaction algorithm. | ||
/// | ||
/// The following are template arguments. | ||
/// K: The type on the key of each record. | ||
/// V: The type on the value stored inside FASTER. | ||
template <class K, class V> | ||
class CompactionDelete : public IAsyncContext { | ||
public: | ||
// Typedefs on the key and value required internally by FASTER. | ||
typedef K key_t; | ||
typedef V value_t; | ||
|
||
// Type signature on the record. Required by the constructor. | ||
typedef Record<K, V> record_t; | ||
|
||
/// Constructs and returns a context given a pointer to a record. | ||
CompactionDelete(record_t* record) | ||
: key_(record->key()) | ||
{} | ||
|
||
/// Copy constructor. Required for when the operation goes async | ||
/// inside FASTER. | ||
CompactionDelete(const CompactionDelete& from) | ||
: key_(from.key_) | ||
{} | ||
|
||
/// Accessor for the key. Invoked from within FASTER. | ||
inline const K& key() const { | ||
return key_; | ||
} | ||
|
||
/// Returns the size of the value. Invoked from within FASTER when creating | ||
/// a new key-value pair (because the key did not map to a value to begin | ||
/// with). | ||
inline static constexpr uint32_t value_size() { | ||
return V::size(); | ||
} | ||
|
||
protected: | ||
/// Copies this context into a passed-in pointer if the operation goes | ||
/// asynchronous inside FASTER. | ||
Status DeepCopy_Internal(IAsyncContext*& context_copy) { | ||
return IAsyncContext::DeepCopy_Internal(*this, context_copy); | ||
} | ||
|
||
private: | ||
/// The key the delete must be performed against. | ||
K key_; | ||
}; | ||
|
||
} // namespace core | ||
} // namespace FASTER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.