/Users/deen/code/yugabyte-db/src/yb/tablet/operations/write_operation.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // |
18 | | // The following only applies to changes made to this file as part of YugaByte development. |
19 | | // |
20 | | // Portions Copyright (c) YugaByte, Inc. |
21 | | // |
22 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
23 | | // in compliance with the License. You may obtain a copy of the License at |
24 | | // |
25 | | // http://www.apache.org/licenses/LICENSE-2.0 |
26 | | // |
27 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
28 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
29 | | // or implied. See the License for the specific language governing permissions and limitations |
30 | | // under the License. |
31 | | // |
32 | | |
33 | | #include "yb/tablet/operations/write_operation.h" |
34 | | |
35 | | #include "yb/consensus/consensus.pb.h" |
36 | | |
37 | | #include "yb/tablet/tablet.h" |
38 | | |
39 | | #include "yb/util/debug-util.h" |
40 | | #include "yb/util/debug/trace_event.h" |
41 | | #include "yb/util/flag_tags.h" |
42 | | #include "yb/util/trace.h" |
43 | | |
44 | | DEFINE_test_flag(int32, tablet_inject_latency_on_apply_write_txn_ms, 0, |
45 | | "How much latency to inject when a write operation is applied."); |
46 | | DEFINE_test_flag(bool, tablet_pause_apply_write_ops, false, |
47 | | "Pause applying of write operations."); |
48 | | TAG_FLAG(TEST_tablet_inject_latency_on_apply_write_txn_ms, runtime); |
49 | | TAG_FLAG(TEST_tablet_pause_apply_write_ops, runtime); |
50 | | |
51 | | namespace yb { |
52 | | namespace tablet { |
53 | | |
54 | | template <> |
55 | | void RequestTraits<WritePB>::SetAllocatedRequest( |
56 | 1.54M | consensus::ReplicateMsg* replicate, WritePB* request) { |
57 | 1.54M | replicate->set_allocated_write(request); |
58 | 1.54M | } |
59 | | |
60 | | template <> |
61 | 4.47M | WritePB* RequestTraits<WritePB>::MutableRequest(consensus::ReplicateMsg* replicate) { |
62 | 4.47M | return replicate->mutable_write(); |
63 | 4.47M | } |
64 | | |
65 | 4.47M | Status WriteOperation::Prepare() { |
66 | 4.47M | TRACE_EVENT0("txn", "WriteOperation::Prepare"); |
67 | 4.47M | return Status::OK(); |
68 | 4.47M | } |
69 | | |
70 | 333 | Status WriteOperation::DoAborted(const Status& status) { |
71 | 333 | TRACE("FINISH: aborting operation"); |
72 | 333 | return status; |
73 | 333 | } |
74 | | |
75 | | // FIXME: Since this is called as a void in a thread-pool callback, |
76 | | // it seems pointless to return a Status! |
77 | 4.47M | Status WriteOperation::DoReplicated(int64_t leader_term, Status* complete_status) { |
78 | 4.47M | TRACE_EVENT0("txn", "WriteOperation::Complete"); |
79 | 4.47M | TRACE("APPLY: Starting"); |
80 | | |
81 | 4.47M | auto injected_latency = GetAtomicFlag(&FLAGS_TEST_tablet_inject_latency_on_apply_write_txn_ms); |
82 | 4.47M | if (PREDICT_FALSE(injected_latency) > 0) { |
83 | 0 | TRACE("Injecting $0ms of latency due to --TEST_tablet_inject_latency_on_apply_write_txn_ms", |
84 | 0 | injected_latency); |
85 | 0 | SleepFor(MonoDelta::FromMilliseconds(injected_latency)); |
86 | 4.47M | } else { |
87 | 4.47M | TEST_PAUSE_IF_FLAG(TEST_tablet_pause_apply_write_ops); |
88 | 4.47M | } |
89 | | |
90 | 4.47M | *complete_status = tablet()->ApplyRowOperations(this); |
91 | | // Failure is regular case, since could happen because transaction was aborted, while |
92 | | // replicating its intents. |
93 | 61.0k | LOG_IF(INFO, !complete_status->ok()) << "Apply operation failed: " << *complete_status; |
94 | | |
95 | | // Now that all of the changes have been applied and the commit is durable |
96 | | // make the changes visible to readers. |
97 | 4.47M | TRACE("FINISH: making edits visible"); |
98 | | |
99 | 4.47M | return Status::OK(); |
100 | 4.47M | } |
101 | | |
102 | 4.76M | HybridTime WriteOperation::WriteHybridTime() const { |
103 | 4.76M | if (request()->has_external_hybrid_time()) { |
104 | 3.40k | return HybridTime(request()->external_hybrid_time()); |
105 | 3.40k | } |
106 | 4.75M | return Operation::WriteHybridTime(); |
107 | 4.75M | } |
108 | | |
109 | | } // namespace tablet |
110 | | } // namespace yb |