Skip to content

Commit 4468ff3

Browse files
committed
chore(meta/service): cleanup long binary data in info level log
1 parent 6b20ef8 commit 4468ff3

File tree

7 files changed

+84
-14
lines changed

7 files changed

+84
-14
lines changed

src/meta/raft-store/src/state_machine/sm.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,7 @@ impl StateMachine {
263263
/// command safely in case of network failure etc.
264264
#[tracing::instrument(level = "debug", skip(self, entry), fields(log_id=%entry.log_id))]
265265
pub async fn apply(&self, entry: &Entry<LogEntry>) -> Result<AppliedState, MetaStorageError> {
266-
info!(
267-
"apply: summary: {}; payload: {:?}",
268-
entry.summary(),
269-
entry.payload
270-
);
266+
info!("apply: summary: {}", entry.summary(),);
271267

272268
let log_id = &entry.log_id;
273269

@@ -280,8 +276,11 @@ impl StateMachine {
280276
txn_sm_meta.insert(&LastApplied, &StateMachineMetaValue::LogId(*log_id))?;
281277

282278
match entry.payload {
283-
EntryPayload::Blank => {}
279+
EntryPayload::Blank => {
280+
info!("apply: blank");
281+
}
284282
EntryPayload::Normal(ref data) => {
283+
info!("apply: {}", data);
285284
if let Some(ref txid) = data.txid {
286285
let (serial, resp) =
287286
self.txn_get_client_last_resp(&txid.client, &txn_tree)?;
@@ -303,7 +302,12 @@ impl StateMachine {
303302
};
304303

305304
let res = self.apply_cmd(&data.cmd, &txn_tree, kv_pairs.as_ref(), log_time_ms);
306-
info!("apply_result: summary: {}; res: {:?}", entry.summary(), res);
305+
if let Ok(ok) = &res {
306+
info!("apply_result: summary: {}; res ok: {}", entry.summary(), ok);
307+
}
308+
if let Err(err) = &res {
309+
info!("apply_result: summary: {}; res err: {:?}", entry.summary(), err);
310+
}
307311

308312
let applied_state = res?;
309313

@@ -317,6 +321,7 @@ impl StateMachine {
317321
return Ok(Some(applied_state));
318322
}
319323
EntryPayload::Membership(ref mem) => {
324+
info!("apply: membership: {:?}", mem);
320325
txn_sm_meta.insert(
321326
&LastMembership,
322327
&StateMachineMetaValue::Membership(EffectiveMembership {
@@ -760,7 +765,7 @@ impl StateMachine {
760765
kv_pairs: Option<&(DeleteByPrefixKeyMap, DeleteByPrefixKeyMap)>,
761766
log_time_ms: u64,
762767
) -> Result<AppliedState, MetaStorageError> {
763-
info!("apply_cmd: {:?}", cmd);
768+
info!("apply_cmd: {}", cmd);
764769

765770
match cmd {
766771
Cmd::IncrSeq { ref key } => self.apply_incr_seq_cmd(key, txn_tree),

src/meta/service/src/api/grpc/grpc_service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ impl MetaService for MetaServiceImpl {
255255

256256
let request = request.into_inner();
257257

258-
info!("Receive txn_request: {:?}", request);
258+
info!("Receive txn_request: {}", request);
259259

260260
let body = self.execute_txn(request).await;
261261
incr_meta_metrics_meta_sent_bytes(body.encoded_len() as u64);

src/meta/service/src/meta_service/meta_leader.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,19 @@ impl<'a> MetaLeader<'a> {
184184
// report metrics
185185
let _guard = WithCount::new((), ProposalPending);
186186

187-
info!("write LogEntry: {:?}", entry);
188-
let write_rst = self.meta_node.raft.client_write(entry).await;
189-
info!("raft.client_write rst: {:?}", write_rst);
187+
info!("write LogEntry: {}", entry);
188+
let write_res = self.meta_node.raft.client_write(entry).await;
189+
if let Ok(ok) = &write_res {
190+
info!(
191+
"raft.client_write res ok: log_id: {}, data: {}, membership: {:?}",
192+
ok.log_id, ok.data, ok.membership
193+
);
194+
}
195+
if let Err(err) = &write_res {
196+
info!("raft.client_write res err: {:?}", err);
197+
}
190198

191-
match write_rst {
199+
match write_res {
192200
Ok(resp) => Ok(resp.data),
193201
Err(cli_write_err) => Err(RaftWriteError::from_raft_err(cli_write_err)),
194202
}

src/meta/types/src/applied_state.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::fmt;
1516
use std::fmt::Debug;
17+
use std::fmt::Formatter;
1618

1719
use openraft::AppDataResponse;
1820
use serde::Deserialize;
@@ -47,6 +49,29 @@ pub enum AppliedState {
4749

4850
impl AppDataResponse for AppliedState {}
4951

52+
impl fmt::Display for AppliedState {
53+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
54+
write!(f, "AppliedState: ")?;
55+
match self {
56+
AppliedState::Seq { seq } => {
57+
write!(f, "Seq: {}", seq)
58+
}
59+
AppliedState::Node { prev, result } => {
60+
write!(f, "Node: prev: {:?}, result: {:?}", prev, result)
61+
}
62+
AppliedState::KV(change) => {
63+
write!(f, "KV: {}", change)
64+
}
65+
AppliedState::TxnReply(txnreply) => {
66+
write!(f, "Txn: {}", txnreply)
67+
}
68+
AppliedState::None => {
69+
write!(f, "None")
70+
}
71+
}
72+
}
73+
}
74+
5075
impl AppliedState {
5176
/// Whether the state changed
5277
pub fn changed(&self) -> bool {

src/meta/types/src/change.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::fmt::Debug;
16+
use std::fmt::Display;
17+
use std::fmt::Formatter;
18+
1519
use serde::Deserialize;
1620
use serde::Serialize;
1721

@@ -104,3 +108,15 @@ where
104108
unreachable!("impossible: both prev and result are None");
105109
}
106110
}
111+
112+
impl<T, ID> Display for Change<T, ID>
113+
where
114+
T: Debug + Clone + PartialEq,
115+
ID: Debug + Clone + PartialEq,
116+
{
117+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
118+
write!(f, "id: {:?}", self.ident)?;
119+
write!(f, "prev: {:?}", self.prev)?;
120+
write!(f, "result: {:?}", self.result)
121+
}
122+
}

src/meta/types/src/cmd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl fmt::Display for Cmd {
7979
write!(f, "upsert_kv:{}", upsert_kv)
8080
}
8181
Cmd::Transaction(txn) => {
82-
write!(f, "txn:{:?}", txn)
82+
write!(f, "txn:{}", txn)
8383
}
8484
}
8585
}

src/meta/types/src/log_entry.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::fmt::Display;
16+
use std::fmt::Formatter;
17+
1518
use openraft::AppData;
1619
use serde::Deserialize;
1720
use serde::Serialize;
@@ -42,3 +45,16 @@ pub struct LogEntry {
4245
}
4346

4447
impl AppData for LogEntry {}
48+
49+
impl Display for LogEntry {
50+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
51+
if let Some(txid) = &self.txid {
52+
write!(f, "txid: {:?}", txid)?;
53+
}
54+
if let Some(time) = &self.time_ms {
55+
write!(f, "time: {} ms", time)?;
56+
}
57+
58+
write!(f, " cmd: {}", self.cmd)
59+
}
60+
}

0 commit comments

Comments
 (0)