Data access checkpoint
Challenge on lesson: Checkpoint: data access
Build class OptimisticStore<T> where T : notnull with void Put(string key, T value, int expectedVersion) and (bool ok, T? value) TryGet(string key) plus int VersionOf(string key). Put stores only if the expected version matches the current one (missing key = expected version 0), increments the version, and throws InvalidOperationException named by message prefix "version conflict" otherwise. Then implement static int SaveAll(OptimisticStore<string> store, List<(string Key, string Value, int Expected)> writes, int maxRounds) that applies writes in rounds โ each round attempts every not-yet-saved write against the current version, counting conflicts โ and returns the number of rounds needed (throw InvalidOperationException if not done within maxRounds).
Back to lesson: Checkpoint: data access