internal DataAccessSessionManager(int readersCount, MemoryAllocator <byte>?sharedPool, int writeBufferSize) { Capacity = readersCount; bufferPool = sharedPool; tokens = readersCount == 1 ? null : new ConcurrentBag <int>(Enumerable.Range(0, readersCount)); WriteSession = new DataAccessSession(0, bufferPool, writeBufferSize); }
public bool GetSetting(SettingLookupInfo lookupInfo, out object value, DataAccessSession dataSession, bool lookForDefault = false) { SettingModel settingModel = GetSettingInfo(lookupInfo.SettingName); string sql = Queries.getSetting; string stringValue = dataSession.LoadData <string, SettingLookupInfo>(sql, lookupInfo).FirstOrDefault(); if (stringValue is null) { if (!lookForDefault) { value = default; return(false); } if (lookupInfo.UId.HasValue && lookupInfo.GId.HasValue && !lookupInfo.CId.HasValue) { lookupInfo.GId = null; return(GetSetting(lookupInfo, out value, lookForDefault)); } if (!lookupInfo.UId.HasValue && lookupInfo.GId.HasValue && lookupInfo.CId.HasValue) { lookupInfo.CId = null; return(GetSetting(lookupInfo, out value, lookForDefault)); } value = settingModel.DefaultValue; return(true); } value = settingModel.Convert(stringValue); return(true); }
public void SetSetting(SettingLookupInfo lookupInfo, object value, DataAccessSession dataSession = null) { string sql; SettingModel settingModel = GetSettingInfo(lookupInfo.SettingName); if (value is null) { sql = Queries.removeSetting; Data.SaveData(sql, lookupInfo); return; } sql = Queries.updateSetting; string stringValue = settingModel.Convert(value); var parameters = new { lookupInfo.SettingName, lookupInfo.Ids, Value = stringValue }; Data.SaveData(sql, parameters); }
private async ValueTask <TResult> ReadAsync <TResult>(LogEntryConsumer <IRaftLogEntry, TResult> reader, DataAccessSession session, long startIndex, long endIndex, CancellationToken token) { if (startIndex > state.LastIndex) { throw new IndexOutOfRangeException(ExceptionMessages.InvalidEntryIndex(endIndex)); } if (endIndex > state.LastIndex) { throw new IndexOutOfRangeException(ExceptionMessages.InvalidEntryIndex(endIndex)); } var length = endIndex - startIndex + 1L; if (length > int.MaxValue) { throw new InternalBufferOverflowException(ExceptionMessages.RangeTooBig); } LogEntry entry; ValueTask <TResult> result; if (partitionTable.Count > 0) { using var list = entryPool.Invoke((int)length, true); var listIndex = 0; for (Partition?partition = null; startIndex <= endIndex; list[listIndex++] = entry, startIndex++) { if (startIndex > 0L && TryGetPartition(startIndex, ref partition, out var switched)) { // handle regular record entry = await partition.ReadAsync(session, startIndex, true, switched, token).ConfigureAwait(false); } else if (snapshot.Length > 0 && startIndex <= state.CommitIndex) { // probably the record is snapshotted entry = await snapshot.ReadAsync(session, token).ConfigureAwait(false); // skip squashed log entries startIndex = SquashedIndex; } else { Debug.Assert(startIndex == 0L); // handle ephemeral entity entry = initialEntry; } } return(await reader.ReadAsync <LogEntry, InMemoryList <LogEntry> >(list.Memory.Slice(0, listIndex), list[0].SnapshotIndex, token).ConfigureAwait(false)); } else if (snapshot.Length > 0) { entry = await snapshot.ReadAsync(session, token).ConfigureAwait(false); result = reader.ReadAsync <LogEntry, SingletonEntryList <LogEntry> >(new SingletonEntryList <LogEntry>(entry), entry.SnapshotIndex, token); } else { result = startIndex == 0L ? reader.ReadAsync <LogEntry, SingletonEntryList <LogEntry> >(new SingletonEntryList <LogEntry>(initialEntry), null, token) : reader.ReadAsync <LogEntry, LogEntry[]>(Array.Empty <LogEntry>(), null, token); } return(await result.ConfigureAwait(false)); }