### Run FixedLenServer from Command Line Source: https://github.com/microsoft/faster/blob/main/docs/_docs/50-remote-basics.md Example command to run the FixedLenServer executable with specified bind address and port. ```bash > FixedLenServer.exe --bind 127.0.0.1 --port 3278 ``` -------------------------------- ### Start FixedLenServer Source: https://github.com/microsoft/faster/blob/main/docs/_docs/50-remote-basics.md Start the FixedLenServer with a sufficiently large hash table (e.g., 8GB) before running the YCSB benchmark. ```bash FixedLenServer -i 8g ``` -------------------------------- ### FasterKV Persistence and Recovery Example Source: https://github.com/microsoft/faster/blob/main/docs/_docs/25-fasterkv-recovery.md Demonstrates how to initialize FasterKV, issue periodic checkpoints, and recover sessions. Use this for setting up persistent storage and resuming operations after a restart. ```csharp public class PersistenceExample { private FasterKV fht; private IDevice log; public PersistenceExample() { log = Devices.CreateLogDevice("C:\\Temp\\hlog.log"); fht = new FasterKV(1L << 20, new LogSettings { LogDevice = log }); } public void Run() { IssuePeriodicCheckpoints(); RunSession(); } public void Continue() { fht.Recover(); IssuePeriodicCheckpoints(); ContinueSession(); } /* Helper Functions */ private void RunSession() { using var session = fht.NewSession(new SimpleFunctions(), "s1"); long seq = 0; // sequence identifier long key = 1, input = 10; while (true) { key = seq % (1L << 20); session.RMW(ref key, ref input, Empty.Default, seq++); } } private void ContinueSession() { using var session = fht.ResumeSession(new SimpleFunctions(), "s1", out CommitPoint cp); // recovered session var seq = cp.UntilSerialNo + 1; long key = 1, input = 10; while (true) { key = seq % (1L << 20); session.RMW(ref key, ref input, Empty.Default, seq++); } } private void IssuePeriodicCheckpoints() { var t = new Thread(() => { while (true) { Thread.Sleep(10000); (_, _) = fht.TakeHybridLogCheckpointAsync(CheckpointType.FoldOver).GetAwaiter().GetResult(); } }); t.Start(); } } ``` -------------------------------- ### Start and Run FASTER Server Source: https://github.com/microsoft/faster/blob/main/docs/_docs/50-remote-basics.md Start the FASTER server to listen for incoming requests and keep it running indefinitely. ```csharp server.Start(); Thread.Sleep(Timeout.Infinite); ``` -------------------------------- ### Configure FasterLog Settings Source: https://github.com/microsoft/faster/blob/main/docs/_docs/43-fasterlog-tuning.md Example of configuring various FasterLog settings including PageSizeBits, MemorySizeBits, and SegmentSizeBits. ```cs var log = new FasterLog(new FasterLogSettings { PageSizeBits = 12, MemorySizeBits = 25, SegmentSizeBits = 30 }); ``` -------------------------------- ### Running FASTER Variable-Length KV Server Source: https://github.com/microsoft/faster/blob/main/docs/_docs/50-remote-basics.md This command starts the FASTER variable-length KV server, specifying the IP address and port to listen on. It also shows example output detailing memory and disk configurations. ```bash > VarLenServer.exe --bind 127.0.0.1 --port 3278 FASTER variable-length KV server Using page size of 32m Using log memory size of 16g There are 512 log pages in memory Using disk segment size of 1g Using hash index size of 64m (1m cache lines) Started server ``` -------------------------------- ### Create SubscribeKVBroker and SubscribeBroker Source: https://github.com/microsoft/faster/blob/main/docs/_docs/51-remote-pubsub.md Instantiate a SubscribeKVBroker for key-value pairs or a SubscribeBroker for patterns. The first argument is an IKeySerializer, the second is the log directory path, and the third indicates whether to start fresh. ```csharp var kvBroker = new SubscribeKVBroker>(new SpanByteKeySerializer(), null, true); var broker = new SubscribeBroker>(new SpanByteKeySerializer(), null, true); ``` -------------------------------- ### Force iterator to start at the beginning Source: https://github.com/microsoft/faster/blob/main/docs/_docs/40-fasterlog-basics.md Initialize an iterator at the specified begin address, ignoring any previously recovered state. Use `recover: false` to prevent state restoration. ```cs using (var iter = log.Scan(0, long.MaxValue, name: "foo", recover: false)) ``` -------------------------------- ### Create Log Device for Blittable Types Source: https://github.com/microsoft/faster/blob/main/docs/_docs/20-fasterkv-basics.md Create a log device for storing data when using blittable types (like long, int, structs) or SpanByte. This example specifies the log file path. ```cs using var log = Devices.CreateLogDevice("c:/temp/hlog.log"); ``` -------------------------------- ### Initialize FASTER Server Source: https://github.com/microsoft/faster/blob/main/docs/_docs/50-remote-basics.md Set up the FASTER server, specifying the IP address and port to bind to, and register the provider for a specific wire format. ```csharp var server = new FasterServer(opts.Address, opts.Port); server.Register(WireFormat.DefaultFixedLenKV, provider); ``` -------------------------------- ### Initialize FasterKV with Log Settings Source: https://github.com/microsoft/faster/blob/main/docs/_docs/23-fasterkv-tuning.md Instantiate FasterKV with custom log settings. Ensure LogSettings is properly configured before passing it to the constructor. ```cs var fht = new FasterKV(1L << 20, new LogSettings { ... }, ...); ``` -------------------------------- ### Truncate Log Until Page Start Source: https://github.com/microsoft/faster/blob/main/docs/_docs/40-fasterlog-basics.md Truncates the log until the start of the page containing the specified address. This is a safe operation as it always targets a valid log boundary. ```cs log.TruncateUntilPageStart(log.CommittedUntilAddress - 100_000_000_000L); ``` -------------------------------- ### FasterKV Basic End-to-End Sample Source: https://github.com/microsoft/faster/blob/main/docs/_docs/20-fasterkv-basics.md This sample demonstrates basic FasterKV operations using in-memory storage and the default SimpleFunctions. It does not involve checkpointing. ```cs public static void Test() { using var settings = new FasterKVSettings("c:/temp"); using var store = new FasterKV(settings); using var session = store.NewSession(new SimpleFunctions((a, b) => a + b)); long key = 1, value = 1, input = 10, output = 0; session.Upsert(ref key, ref value); session.Read(ref key, ref output); Debug.Assert(output == value); session.RMW(ref key, ref input); session.RMW(ref key, ref input, ref output); Debug.Assert(output == value + 20); } ``` -------------------------------- ### Instantiate FasterKV with Default Settings Source: https://github.com/microsoft/faster/blob/main/docs/_docs/20-fasterkv-basics.md Create a FasterKV instance for long keys and string values, storing data in a specified directory. Uses default settings for other parameters. ```cs using var settings = new FasterKVSettings("c:/temp"); using var store = new FasterKV(settings); ``` -------------------------------- ### Asynchronous Read Operation Source: https://github.com/microsoft/faster/blob/main/docs/_docs/20-fasterkv-basics.md Perform an asynchronous read operation and complete it. The `Complete()` method is used to get the final status and output. ```cs // Async var (status, output) = (await session.ReadAsync(key, input)).Complete(); ``` -------------------------------- ### Instantiate FasterKV with Explicit Device Settings Source: https://github.com/microsoft/faster/blob/main/docs/_docs/20-fasterkv-basics.md Instantiate FasterKV by providing explicitly created log and object log devices via FasterKVSettings. This allows for more control over storage configuration. ```cs using var settings = new FasterKVSettings { LogDevice = log, ObjectLogDevice = objlog }; using var store = new FasterKV(settings); ``` -------------------------------- ### Run Recovery Test - Recover to Specific Checkpoint Source: https://github.com/microsoft/faster/blob/main/cs/playground/SumStore/README.md Recovers the test to a specific checkpoint using GUIDs. Specify the number of threads. ```bash SumStore.exe recovery_test 2 recover SINGLE_GUID ``` ```bash SumStore.exe recovery_test 2 recover INDEX_GUID LOG_GUID ``` -------------------------------- ### Initialize FasterLog with Settings Source: https://github.com/microsoft/faster/blob/main/docs/_docs/43-fasterlog-tuning.md Instantiate FasterLog with custom settings using the FasterLogSettings object. ```cs var log = new FasterLog(new FasterLogSettings { ... }); ``` -------------------------------- ### Instantiate FasterKv with Detailed Configuration Source: https://github.com/microsoft/faster/blob/main/docs/_docs/29-fasterkv-cpp.md Instantiates a FasterKv store using a detailed configuration object, enabling read-cache and automatic hybrid log compactions with specific parameters for each component. ```cpp // Configure hash index typedef FasterKv::IndexConfig IndexConfig; IndexConfig index_config { .num_buckets = 2 * (1 << 20); // 2M buckets }; // Configure hybrid log HlogConfig log_config { .in_mem_size = 4*(1 << 30), // 4 GiB in-mem log size .mutable_fraction = 0.9, // 90% mutable .pre_allocate = false // Do not pre-allocate log }; // Configure read cache ReadCacheConfig rc_config { .mem_size = 512 * (1 << 20), // 512 MiB cache .mutable_fraction = 0.5, // 50% .pre_allocate = false, // Do not pre-allocate .enabled = true // Enable read-cache }; // Configure hlog compaction policy HlogCompactionConfig hc_config{ .check_interval = 250ms, .trigger_pct = 0.8, .compact_pct = 0.2, .hlog_size_budget = 10 * (1 << 30ULL), .max_compacted_size = 1 * (1 << 30), .num_threads = 4, .enabled = true // Enabled automatic compactions }; // Create FasterKv instance typedef FasterKv::Config Config; FasterKv store{ Config{ index_config, log_config, "hlog", rc_config, hc_config } }; ``` -------------------------------- ### Initialize FASTER Client Source: https://github.com/microsoft/faster/blob/main/docs/_docs/50-remote-basics.md Instantiate a FASTER client by specifying the server IP address and port. Ensure the key and value types are compatible with the server. ```cs using var client = new FasterKVClient(ip, port); ``` -------------------------------- ### Instantiate FasterKv with Basic Options Source: https://github.com/microsoft/faster/blob/main/docs/_docs/29-fasterkv-cpp.md Instantiates a FasterKv store with specified hash table size, in-memory log size, log path, and mutable fraction. Pre-allocation is disabled by default. ```cpp // Create FasterKv instance with: // - 1M hash table entries // - 1GB log size // - 90% mutable fraction // - No pre-allocation FasterKv store{ 2 * (1 << 20), // Hash table size (2M entries) 4 * (1 << 30), // In-memory Log size (4 GiB) "/path/to/hlog-dir", // Log path 0.9, // Log Mutable fraction }; ``` -------------------------------- ### FASTER WebClient Read Operation Source: https://github.com/microsoft/faster/blob/main/cs/remote/samples/WebClient/WebClient.html Handles the 'Get' button click to retrieve a value by its key. It serializes the key and then calls the Read operation. Ensure `getKey` element is correctly referenced. ```javascript function onClickButtonGet() { var keyBytes = serialize(getKey.value); remoteSession.Read(keyBytes); remoteSession.CompletePending(true); } ``` -------------------------------- ### Initialize FasterKV Store with Disk Persistence Source: https://github.com/microsoft/faster/blob/main/docs/_docs/29-fasterkv-cpp.md Configure and initialize an F2Kv store for disk-based persistence, specifying parameters for hot and cold stores, read cache, and compaction. ```cpp #include "faster.h" // Define key, value and device types struct Key { /* ... */ }; struct Value { /* ... */ }; // Create hot and cold store configurations typename F2Kv::HotIndexConfig HotIndexConfig typename F2Kv::ColdIndexConfig ColdIndexConfig; // Index configuration for hot, cold stores HotIndexConfig hot_index_config { .table_size = (1 << 30) // 1M hot index hash table size }; ColdIndexConfig cold_index_config { .table_size = (1 << 30), // 1M cold index buckets (8M entries) .in_mem_size = 192 * (1 << 20),// 192 MiB in-memory region .mutable_fraction = 0.4 // 40% mutable }; // Enable in-memoy read-cache (default size: 256 MiB) ReadCacheConfig rc_config = DEFAULT_READ_CACHE_CONFIG; rc_config.enabled = true; // Enable automatic compactions for both hot, cold stores // - Hot log total budget: 2 GiB // - Cold log total budget 8 GiB F2CompactionConfig compaction_config = DEFAULT_F2_COMPACTION_CONFIG; compaction_config.hot_store.hlog_size_budget = 2 * (1 << 30UL); compaction_config.cold_store.hlog_size_budget = 8 * (1 << 30UL); // Initialize F2Kv store F2Kv store( hot_index_config, // Hot store index configuration (1 << 30), // Hot store memory size (1 GiB) "/path/to/disk/hot-log", // Hot store log dir cold_config, // Cold store index configuration 192 * (1 << 20), // Cold store memory size (192 MiB) "/path/to/disk/cold-log", // Cold store log dir 0.9, // Hot store mutable fraction 0.0 // Cold store mutable fraction rc_config, // Read-cache configuration compaction_config // Hlogs compaction configuration ); ``` -------------------------------- ### Create FasterLog Instance Source: https://github.com/microsoft/faster/blob/main/docs/_docs/40-fasterlog-basics.md Instantiate FasterLog with default settings using a specified directory. The 'using' statement ensures proper disposal of resources. ```csharp using var config = new FasterLogSettings("d:/fasterlog"); using var log = new FasterLog(config); ``` -------------------------------- ### Create FASTER KV Store Instance Source: https://github.com/microsoft/faster/blob/main/docs/_docs/50-remote-basics.md Instantiate a FasterKV store, with options to recover from a checkpoint. ```csharp var store = new FasterKV(indexSize, logSettings, checkpointSettings); ``` -------------------------------- ### Embedded Key-Value Store Sample Source: https://github.com/microsoft/faster/blob/main/docs/_docs/01-quick-start-guide.md Demonstrates basic operations of an embedded key-value store using FASTER, including upsert, read, and read-modify-write operations. Requires a log device for backing storage and a session with custom merge functions. ```cs public static void Main() { using var log = Devices.CreateLogDevice("hlog.log"); // backing storage device using var store = new FasterKV(1L << 20, // hash table size (number of 64-byte buckets) new LogSettings { LogDevice = log } // log settings (devices, page size, memory size, etc.) ); // Create a session per sequence of interactions with FASTER // We use default callback functions with a custom merger: RMW merges input by adding it to value using var s = store.NewSession(new SimpleFunctions((a, b) => a + b)); long key = 1, value = 1, input = 10, output = 0; // Upsert and Read s.Upsert(ref key, ref value); s.Read(ref key, ref output); Debug.Assert(output == value); // Read-Modify-Write (add input to value) s.RMW(ref key, ref input); s.RMW(ref key, ref input); s.Read(ref key, ref output); Debug.Assert(output == value + 20); Console.WriteLine("Success!"); } ``` -------------------------------- ### Perform Async Operations with FasterKV Source: https://github.com/microsoft/faster/blob/main/docs/_docs/29-fasterkv-cpp.md Demonstrates how to perform asynchronous Upsert, Read, and RMW operations on an F2Kv store using callbacks and session management. ```cpp // F2Kv store{ ... } // Define operation contexts for // Read, Upsert, and RMW operations class ReadContext : public IAsyncContext { ... }; class UpsertContext : public IAsyncContext { ... }; class RmwContext : public IAsyncContext { ... }; // Callback for async operations auto callback = [](IAsyncContext* ctxt, Status result) { if (result != Status::Ok) { std::cerr << "Error in async operation!" << std::endl; } }; // Start a session auto session_id = store.StartSession(); // Perform operations { // Upsert UpsertContext upsert_context{ Key{1}, Value{100} }; store.Upsert(upsert_context, callback, 1); // Read ReadContext read_context{ Key{1} }; Status result = store.Read(read_context, callback, 2); if (result == Status::Ok) { std::cout << "Read value: " << read_context.value << std::endl; } // RMW (increment by 50) RmwContext rmw_context{ Key{1}, Value{50} }; store.Rmw(rmw_context, callback, 3); // Complete any pending operations store.CompletePending(true); // Read updated value ReadContext read_context2{ Key{1} }; result = store.Read(read_context2, callback, 4); if (result == Status::Ok) { std::cout << "Updated value: " << read_context2.value << std::endl; } } // Stop session store.StopSession(); ``` -------------------------------- ### Create Local Log Device Source: https://github.com/microsoft/faster/blob/main/docs/_docs/43-fasterlog-tuning.md Easily create an instance of a local storage device for the log. The device should be disposed of via IDisposable. ```cs var log = Devices.CreateLogDevice(Path.GetTempPath() + "hlog.log"); ``` -------------------------------- ### Initialize FasterKV with Index Size (C#) Source: https://github.com/microsoft/faster/blob/main/docs/_docs/23-fasterkv-tuning.md Instantiate FasterKV with a specified index size. This parameter determines the number of main hash buckets. ```csharp store = new FasterKV(indexSize, ...); ``` -------------------------------- ### Initialize FasterKV with Index Size (C++) Source: https://github.com/microsoft/faster/blob/main/docs/_docs/23-fasterkv-tuning.md Instantiate FasterKv with a specified index size. This parameter determines the number of main hash buckets. ```cpp FasterKv store{ index_size, ... }; ``` -------------------------------- ### Run FASTER Benchmark Source: https://github.com/microsoft/faster/wiki/Performance-of-FASTER-in-C Use these commands to run the FASTER benchmark. Adjust parameters like -b (system), -t (threads), -n (NUMA sockets), and -r (read percentage) as needed. ```bash FASTER.benchmark.exe -b 0 -t 1 -n 1 -r 0 FASTER.benchmark.exe -b 0 -t 2 -n 1 -r 0 ``` -------------------------------- ### Session Creation Source: https://github.com/microsoft/faster/blob/main/docs/_docs/20-fasterkv-basics.md Demonstrates how to create a new session for performing operations on FASTER. ```APIDOC ## Session Creation FASTER allows users to issue operations through logical sessions. A session represents a single-threaded sequence of operations. ### Example 1: Standard Session Creation ```cs using var session = store.NewSession(new Functions()); ``` ### Example 2: Optimized Session Creation This version is more optimized as it avoids interface calls. ```cs using var session = store.For(new Functions()).NewSession(); ``` ``` -------------------------------- ### Create a New Session Source: https://github.com/microsoft/faster/blob/main/docs/_docs/20-fasterkv-basics.md Instantiate a new logical session for performing operations on FASTER KV. The `Functions` type should be specified. ```cs using var session = store.NewSession(new Functions()); ``` ```cs using var session = store.For(new Functions()).NewSession(); ``` -------------------------------- ### Embedded Key-Value Store Sample in C# Source: https://github.com/microsoft/faster/blob/main/docs/_pages/home.md Demonstrates basic operations of the FASTER embedded key-value store, including initialization, session creation, upsert, read, and read-modify-write operations. Requires FASTER NuGet packages. ```csharp public static void Test() { using var settings = new FasterKVSettings("c:/temp"); // backing storage device using var store = new FasterKV(settings); // Create a session per sequence of interactions with FASTER // We use default callback functions with a custom merger: RMW merges input by adding it to value using var session = store.NewSession(new SimpleFunctions((a, b) => a + b)); long key = 1, value = 1, input = 10, output = 0; // Upsert and Read session.Upsert(ref key, ref value); session.Read(ref key, ref output); Debug.Assert(output == value); // Read-Modify-Write (add input to value) session.RMW(ref key, ref input); session.RMW(ref key, ref input, ref output); Debug.Assert(output == value + 20); } ``` -------------------------------- ### Advanced FasterKV Configuration in C++ Source: https://github.com/microsoft/faster/blob/main/docs/_docs/29-fasterkv-cpp.md Configure every aspect of F2Kv, including separate compaction behavior for hot and cold stores, and non-default cold-index hash chunk size. Ensure correct types and configurations are used for both hot and cold stores. ```cpp // Define your types struct Key { /* ... */ }; struct Value { /* ... */ }; // Hot Index class using HI = MemHashIndex; // Cold Index class: Use 2^6 (=64 byte) sized hash chunks using CI = ColdIndex>; // F2Kv specialized class using store_t = F2Kv; // Create hot and cold store configurations // Create hot store configuration typename store_t::HotIndexConfig HotIndexConfig typename store_t::hot_faster_store_config_t hot_config; hot_config.filepath = "/path/to/disk/hot-store/"; // Configure hot store's index hot_config.index_config = HotIndexConfig{ .table_size = (1 << 30) // 1M hot index hash table size } // Configure hot store's hybrid log hot_config.hlog_config = HlogConfig{ .in_mem_size = (1 << 30UL), // 1 GiB memory size .mutable_fraction = 0.6, // 60% mutable region .pre_allocate = true // Pre-allocate memory }; // Configure hot store compaction hot_config.hlog_copaction_config = HlogCompactionConfig { .check_interval = 500ms, // Check every 0.5 second .trigger_pct = 0.8, .compact_pct = 0.2, .max_compacted_size = 512 * (1 << 20), // Compact up to 512 MiB .hlog_size_budget = 2 * (1 << 30), // 2 GiB total disk budget .num_threads = 8, // Use 8 threads .enabled = true }; // Configure (hot store) read cache hot-config.rc_config = ReadCacheConfig{ .mem_size = 256_MiB, .mutable_fraction = 0.5, .pre_allocate_log = false, .enabled = true }; // Create cold store configuration typename store_t::cold_faster_store_config_t cold_config; typename store_t::ColdIndexConfig ColdIndexConfig; cold_config.filepath = "/path/to/disk/cold-store/"; // Configure cold store's index cold_config.index_config { .table_size = (1 << 30), // 1M cold index buckets (8M entries) .in_mem_size = 192 * (1 << 20),// 192 MiB in-memory region .mutable_fraction = 0.4 // 40% mutable }; // Configure cold store's hybrid log cold_config.hlog_config = HlogConfig{ .in_mem_size = (192 << 20UL), // 192 MiB memory size .mutable_fraction = 0.4, // 40% mutable region .pre_allocate = false // Do not pre-allocate memory }; // Configure cold store compaction cold_config.hlog_copaction_config = HlogCompactionConfig { .check_interval = 2000ms, // Check every 2 seconds .trigger_pct = 0.9, .compact_pct = 0.1, .max_compacted_size = (1 << 30), // Compact up to 1 GiB .hlog_size_budget = 16 * (1 << 30UL), // 16 GiB total disk budget .num_threads = 4, // Use 4 threads .enabled = true }; // Create F2Kv instance store_t store{ hot_config, cold_config }; // Insert/Read/Update records... ... ``` -------------------------------- ### WebClient Event Listeners and Session Initialization Source: https://github.com/microsoft/faster/blob/main/cs/remote/samples/WebClient/WebClient.html Sets up event listeners for UI buttons and initializes the FASTER client session. The address and port should be configured for your FASTER service. ```javascript // http://www.websocket.org/echo.html var buttonPut = document.querySelector("#putButton"), buttonGet = document.querySelector("#getButton"), buttonSub = document.querySelector("#subButton"); buttonPut.addEventListener("click", onClickButtonPut); buttonGet.addEventListener("click", onClickButtonGet); buttonSub.addEventListener("click", onClickButtonSub); var address = "127.0.0.1"; var port = 3278; var remoteSession = new ClientSession(address, port, new FASTERFunctions(this)); ``` -------------------------------- ### Run ConcurrentDictionary Benchmark Source: https://github.com/microsoft/faster/wiki/Performance-of-FASTER-in-C Use these commands to run the ConcurrentDictionary benchmark. Adjust parameters like -b (system), -t (threads), -n (NUMA sockets), and -r (read percentage) as needed. ```bash FASTER.benchmark.exe -b 1 -t 1 -n 1 -r 0 FASTER.benchmark.exe -b 1 -t 2 -n 1 -r 0 ``` -------------------------------- ### Construct FASTER KV Provider Source: https://github.com/microsoft/faster/blob/main/docs/_docs/50-remote-basics.md Create a session provider for the store, capable of handling specific wire formats like fixed-length types. ```csharp var provider = new FasterKVProvider>(store, e => new Functions()); ``` -------------------------------- ### Instantiate FasterKV for In-Memory Operation Source: https://github.com/microsoft/faster/blob/main/docs/_docs/20-fasterkv-basics.md Create a FasterKV instance for in-memory operation by specifying null for the storage path. This is useful for testing or scenarios where persistence is not required. ```cs using var settings = new FasterKVSettings(null); using var store = new FasterKV(settings); ``` -------------------------------- ### Take Full Checkpoint Source: https://github.com/microsoft/faster/blob/main/docs/_docs/25-fasterkv-recovery.md Combines index and log checkpointing. Use with caution for large indexes; consider frequent log-only checkpoints. ```cs await store.TakeFullCheckpointAsync(CheckpointType.FoldOver); ``` -------------------------------- ### Subscribe to a Key or Pattern in FasterKV Source: https://github.com/microsoft/faster/blob/main/docs/_docs/51-remote-pubsub.md Use clientSession to subscribe to keys or glob-style patterns that are stored within the FasterKV store. ```csharp clientSession.SubscribeKV(key); // Used for subscribing to a key that is stored in FasterKV clientSession.PSubscribe(pattern); // Used for subscribing to a glob-style pattern that is stored in FasterKV ``` -------------------------------- ### Take Index Checkpoint Source: https://github.com/microsoft/faster/blob/main/docs/_docs/25-fasterkv-recovery.md Initiates an index-only checkpoint. This is the first step in a two-part checkpointing process. ```cs await store.TakeIndexCheckpointAsync(); ``` -------------------------------- ### Basic FasterKv C++ Usage Source: https://github.com/microsoft/faster/blob/main/docs/_docs/29-fasterkv-cpp.md Initializes FasterKv, performs Upsert, Read, and RMW operations, and completes pending tasks. Ensure correct Key, Value, and Context types are defined. The callback function handles results of asynchronous operations. ```cpp #include "faster.h" using namespace FASTER::core; // Define key and value types struct Key { ... } struct Value { ... }; // Define operation contexts for // Read, Upsert, and RMW operations class ReadContext : public IAsyncContext { ... }; class UpsertContext : public IAsyncContext { ... }; class RmwContext : public IAsyncContext { ... }; int main() { // Initialize FasterKv setting uint64_t hash_table_size = 1 << 20; // 1 M hash table entries uint64_t log_size = 4 * (1 << 30); // 4 GiB log size const char* log_path = "/path/to/hlog"; double mutable_fraction = 0.9; // 90% mutable region // Create FasterKv instance FasterKv store{ hash_table_size, log_size, log_path, mutable_fraction }; // Callback for async operations auto callback = [](IAsyncContext* ctxt, Status result) { if (result != Status::Ok) { std::cerr << "Error in async operation!" << std::endl; } }; // Start a session auto session_id = store.StartSession(); // Perform operations { // Upsert UpsertContext upsert_context{ Key{1}, Value{100} }; store.Upsert(upsert_context, callback, 1); // Read ReadContext read_context{ Key{1} }; Status result = store.Read(read_context, callback, 2); if (result == Status::Ok) { std::cout << "Read value: " << read_context.value << std::endl; } // RMW (increment by 50) RmwContext rmw_context{ Key{1}, Value{50} }; store.Rmw(rmw_context, callback, 3); // Complete any pending operations store.CompletePending(true); // Read updated value ReadContext read_context2{ Key{1} }; result = store.Read(read_context2, callback, 4); if (result == Status::Ok) { std::cout << "Updated value: " << read_context2.value << std::endl; } } // Stop session store.StopSession(); return 0; } ``` -------------------------------- ### Build SumStore Executable with CMake Source: https://github.com/microsoft/faster/blob/main/cc/playground/sum_store-dir/CMakeLists.txt Defines the headers and source files for the sum_store executable and links necessary libraries. Ensure SUM_STORE_HEADERS and FASTER_BENCHMARK_LINK_LIBS are defined elsewhere in the CMake configuration. ```cmake set(SUM_STORE_HEADERS concurrent_recovery_test.h single_threaded_recovery_test.h sum_store.h ) add_executable(sum_store ${SUM_STORE_HEADERS} sum_store.cc) target_link_libraries(sum_store ${FASTER_BENCHMARK_LINK_LIBS}) ``` -------------------------------- ### Helper: Enqueue and Wait for Commit Source: https://github.com/microsoft/faster/blob/main/docs/_docs/40-fasterlog-basics.md Convenience methods to enqueue an entry and wait for its persistence. These helpers do not issue commits themselves, encouraging batched commits for performance. ```cs long EnqueueAndWaitForCommit(byte[] entry) async ValueTask EnqueueAndWaitForCommitAsync(byte[] entry) ``` -------------------------------- ### Dispose FasterKV Store and Settings Source: https://github.com/microsoft/faster/blob/main/docs/_docs/20-fasterkv-basics.md After all sessions are disposed, dispose of the main FasterKV store and its settings to fully release all resources. This should be done as the last step in resource cleanup. ```cs store.Dispose(); settings.Dispose(); ``` -------------------------------- ### Define Benchmark Headers Source: https://github.com/microsoft/faster/blob/main/cc/benchmark-dir/CMakeLists.txt Sets a list of header files to be used for benchmarks. Include this before defining benchmark targets. ```cmake set(BENCHMARK_HEADERS benchmark.h file.h ) ``` -------------------------------- ### FasterKv Configuration Structure Source: https://github.com/microsoft/faster/blob/main/docs/_docs/29-fasterkv-cpp.md Defines the structure for FasterKv configuration, encompassing settings for the hash index, hybrid log, read-cache, and compaction policy, along with the file path. ```cpp struct FasterKvConfig { IndexConfig index_config; // Hash index HlogConfig hlog_config; // Hybrid log ReadCacheConfig rc_config; // Read-cache HlogCompactionConfig hlog_compaction_config; // Compaction policy std::string filepath; // Path on disk } ``` -------------------------------- ### Subscribe to a Key or Pattern Source: https://github.com/microsoft/faster/blob/main/docs/_docs/51-remote-pubsub.md Use clientSession to subscribe to specific keys or glob-style patterns. This is used for subscriptions where keys are not stored in FasterKV. ```csharp clientSession.Subscribe(key); // Used for subscribing to a key that is not stored in FasterKV clientSession.PSubscribe(pattern); // Used for subscribing to a glob-style pattern that is not stored in FasterKV ``` -------------------------------- ### Session Management Source: https://github.com/microsoft/faster/blob/main/docs/_docs/29-fasterkv-cpp.md Methods for initiating, resuming, and ending sessions within FasterKV. ```APIDOC ## StartSession ### Description Initiates a new session and returns a session identifier. ### Method (Not specified, likely a constructor or factory method) ### Endpoint N/A (C++ API) ### Parameters None explicitly mentioned. ### Response - session identifier (type not specified) ``` ```APIDOC ## ContinueSession ### Description Resumes an existing session identified by the provided GUID. ### Method (Not specified, likely a method call) ### Endpoint N/A (C++ API) ### Parameters - **guid** (Guid) - Description: The unique identifier of the session to resume. ### Response (Not specified) ``` ```APIDOC ## StopSession ### Description Ends the current session. ### Method (Not specified, likely a method call) ### Endpoint N/A (C++ API) ### Parameters None explicitly mentioned. ### Response (Not specified) ``` -------------------------------- ### Bump Current Epoch for Page Eviction Handling Source: https://github.com/microsoft/faster/blob/main/docs/_docs/30-fasterkv-record-locking.md This code demonstrates how to bump the current epoch to handle page evictions. It involves a callback function that is executed when pages are ready to be closed, allowing for the transfer of locks. ```csharp epoch.BumpCurrentEpoch(() => OnPagesReadyToClose(oldTentativeHeadAddress, newHeadAddress)); ``` -------------------------------- ### Snapshot Hybrid Log Checkpoint Source: https://github.com/microsoft/faster/blob/main/docs/_docs/20-fasterkv-basics.md Creates a checkpoint by taking a snapshot of in-memory data into a separate file, allowing in-place updates to continue in the mutable log. This is useful for minimizing downtime during checkpointing. ```cs await store.TakeHybridLogCheckpointAsync(CheckpointType.Snapshot); ``` -------------------------------- ### Specify Log Commit File Directory Source: https://github.com/microsoft/faster/blob/main/docs/_docs/43-fasterlog-tuning.md Use LogCommitFile as a shortcut to specify the directory for storing and retrieving checkpoints. ```cs var log = new FasterLog(new FasterLogSettings { LogCommitFile = "/path/to/checkpoints/" }); ``` -------------------------------- ### Create Remote Client Session Source: https://github.com/microsoft/faster/blob/main/docs/_docs/50-remote-basics.md Create a new client session with the specified functions and wire format. The session is mono-threaded and handles operations serially. ```cs using var session = client.NewSession(new Functions(), WireFormat.DefaultFixedLenKV); ``` -------------------------------- ### Configure Memory Allocation Callback Source: https://github.com/microsoft/faster/blob/main/docs/_docs/43-fasterlog-tuning.md Provide a custom callback function for allocating memory for read entries. ```cs var log = new FasterLog(new FasterLogSettings { GetMemory = (size) => NativeMemory.AlignedAlloc((nuint)size, 0x1000) }); ``` -------------------------------- ### Run FASTER YCSB Benchmark (Skip Load) Source: https://github.com/microsoft/faster/blob/main/docs/_docs/50-remote-basics.md Re-run the FASTER YCSB benchmark without the data loading phase using the `-s` option. ```bash FASTER.benchmark -b 0 -t 8 -r 50 -d zipf -i 127.0.0.1 -p 3278 -s ``` -------------------------------- ### Build read_index_metadata Executable with FASTER Libraries Source: https://github.com/microsoft/faster/blob/main/cc/playground/recovery-info/CMakeLists.txt Defines the 'read_index_metadata' executable and links it with the FASTER benchmark libraries. Use this to build the index metadata reader utility. ```cmake add_executable(read_index_metadata read_index_metadata.cc) target_link_libraries(read_index_metadata ${FASTER_BENCHMARK_LINK_LIBS}) ``` -------------------------------- ### Configure C++ FASTER build on Linux (Release) Source: https://github.com/microsoft/faster/blob/main/docs/_docs/29-fasterkv-cpp.md Configure the C++ FASTER build for Release mode on Linux using CMake. This command should be run from a separate build directory. ```sh cmake -DCMAKE_BUILD_TYPE=Release ../.. ``` -------------------------------- ### Build read_log_metadata Executable with FASTER Libraries Source: https://github.com/microsoft/faster/blob/main/cc/playground/recovery-info/CMakeLists.txt Defines the 'read_log_metadata' executable and links it with the FASTER benchmark libraries. Use this to build the log metadata reader utility. ```cmake add_executable(read_log_metadata read_log_metadata.cc) target_link_libraries(read_log_metadata ${FASTER_BENCHMARK_LINK_LIBS}) ``` -------------------------------- ### Create Object Log Device for Serializable Types Source: https://github.com/microsoft/faster/blob/main/docs/_docs/20-fasterkv-basics.md Create a separate object log device for storing serializable C# objects like classes and strings. This is necessary when keys or values are not blittable types. ```cs using var objlog = Devices.CreateLogDevice("c:/temp/hlog.obj.log"); ``` -------------------------------- ### Enqueue Operations in FasterLog Source: https://github.com/microsoft/faster/blob/main/docs/_docs/40-fasterlog-basics.md These methods insert entries into the log in memory. Use Enqueue for blocking inserts, TryEnqueue for non-blocking inserts with space checking, and EnqueueAsync for asynchronous inserts. ```cs long Enqueue(byte[] entry) bool TryEnqueue(byte[] entry, out long logicalAddress) async ValueTask EnqueueAsync(byte[] entry) ``` -------------------------------- ### Take Snapshot Log Checkpoint Source: https://github.com/microsoft/faster/blob/main/docs/_docs/25-fasterkv-recovery.md Performs a snapshot of the hybrid log. Set `tryIncremental` to true for incremental snapshots. ```cs await store.TakeHybridLogCheckpointAsync(CheckpointType.Snapshot, tryIncremental: false); ```