// TODO: Currenly the last items are omitted with this variant. Use Listen() instead. public async IAsyncEnumerable <(string, long, long)> ListenAsync_(int flushSize) { // Always start from beginning. Assume it is refilled or truncate works. using (FasterLogScanIterator iter = logger.Scan(0, 1_000_000_000, name: "listen")) { int i = 0; await foreach ((byte[] bytes, int length) in iter.GetAsyncEnumerable()) { if (i >= flushSize) { nextAddress = iter.NextAddress; break; } CancellationTokenSource cts = new CancellationTokenSource(); UTF8Encoding encoding = new UTF8Encoding(); i++; // Probably shouldn't wait // - https://microsoft.github.io/FASTER/docs/fasterlog#iteration yield return(encoding.GetString(bytes), iter.CurrentAddress, iter.NextAddress); } } }
public async IAsyncEnumerable <(string, long, long)> GetListAsync() { using (FasterLogScanIterator iter = logger.Scan(nextAddress, 100_000_000)) { int i = 0; await foreach ((byte[] bytes, int length) in iter.GetAsyncEnumerable()) { if (i > 50) { nextAddress = iter.NextAddress; break; } CancellationTokenSource cts = new CancellationTokenSource(); UTF8Encoding encoding = new UTF8Encoding(); try { await Task.WhenAny(WaitAsync(iter, cts.Token), SetTimeout(cts)); i++; } catch (Exception) { break; } yield return(encoding.GetString(bytes), iter.CurrentAddress, iter.NextAddress); } } }
static async Task AsyncScan() { await foreach ((byte[] result, int length, long currentAddress) in iter.GetAsyncEnumerable()) { if (Different(result, staticEntry)) { throw new Exception("Invalid entry found"); } log.TruncateUntilPageStart(iter.NextAddress); } }
static async Task AsyncScan() { using (iter = log.Scan(log.BeginAddress, long.MaxValue)) await foreach ((byte[] result, int length) in iter.GetAsyncEnumerable()) { if (Different(result, staticEntry, out int location)) { throw new Exception("Invalid entry found"); } log.TruncateUntil(iter.NextAddress); } }
public async Task <List <(string, long, long)> > StartScan(string devicePath) { IDevice device = Devices.CreateLogDevice(devicePath); FasterLog logger = new FasterLog(new FasterLogSettings { LogDevice = device }); long nextAddress = 0; bool keepGoing = true; int i = 0; var result = new List <(string, long, long)>(); // using (FasterLogScanIterator iter = logger.Scan(logger.BeginAddress, 100_000_000, name: nameof(GetListAsync))) using (FasterLogScanIterator iter = logger.Scan(nextAddress, 1_000_000_000)) { while (keepGoing) { Console.WriteLine("Going"); LocalTime timeOfDay; await foreach ((byte[] bytes, int length) in iter.GetAsyncEnumerable()) { DateTimeZone tz = DateTimeZoneProviders.Tzdb.GetSystemDefault(); timeOfDay = SystemClock.Instance.GetCurrentInstant().InZone(tz).TimeOfDay; nextAddress = iter.NextAddress; Console.WriteLine("Time={1} NextAddress={0}, Count={2}", iter.NextAddress, timeOfDay, i++); var cts = new CancellationTokenSource(); UTF8Encoding encoding = new UTF8Encoding(); try { await Task.WhenAny(WaitAsync(iter), SetTimeout(cts)); } catch (Exception e) { Console.Error.WriteLine($"Error={e.GetType()}, Message={e.ToString()}"); break; } timeOfDay = SystemClock.Instance.GetCurrentInstant().InZone(tz).TimeOfDay; Console.WriteLine("Time={2} ContentLength={0}", bytes.Length, iter.NextAddress, timeOfDay); } await Task.Delay(5000); } } return(result); }