xref: /aosp_15_r20/external/federated-compute/fcp/client/opstats/opstats_db.h (revision 14675a029014e728ec732f129a32e299b2da0601)
1 /*
2  * Copyright 2021 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef FCP_CLIENT_OPSTATS_OPSTATS_DB_H_
17 #define FCP_CLIENT_OPSTATS_OPSTATS_DB_H_
18 
19 #include <functional>
20 
21 #include "absl/status/status.h"
22 #include "absl/status/statusor.h"
23 #include "fcp/protos/opstats.pb.h"
24 
25 namespace fcp {
26 namespace client {
27 namespace opstats {
28 
29 // Base no-op class for the OpStats database that always contains an empty
30 // OpStatsSequence and performs no file i/o.
31 class OpStatsDb {
32  public:
33   virtual ~OpStatsDb() = default;
34   // The returned OpStatsSequence message should contain the operational stats
35   // for all runs.  The operational stats for each run is wrapped inside a
36   // OperationalStats message, and the OperationalStats messages are ordered
37   // sequentially (first run to last run) within OpStatsSequence.
Read()38   virtual absl::StatusOr<OpStatsSequence> Read() { return OpStatsSequence(); }
39 
40   // OpStatsDb has a Transform method instead of a Write method because
41   // OpStatsSequence message already contains the operational stats for every
42   // run, and the user only need to update the existing OpStatsSequence message
43   // to add/remove/update data. In addition, by having a Transform method allows
44   // the implementations to perform atomic read-update-write operations.
Transform(std::function<void (OpStatsSequence &)> func)45   virtual absl::Status Transform(std::function<void(OpStatsSequence&)> func) {
46     return absl::OkStatus();
47   }
48 };
49 
50 }  // namespace opstats
51 }  // namespace client
52 }  // namespace fcp
53 
54 #endif  // FCP_CLIENT_OPSTATS_OPSTATS_DB_H_
55