-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
logger: initial commit of klog functionality for segcache-rs
Adds a new logger which has command logger specific functionality. Adds command logging to pelikan_segcache_rs. Changes to the memcache wire protocol to support providing the necessary context for command logging. Fixes `cas` operation in seg storage implementation.
- Loading branch information
Showing
43 changed files
with
1,621 additions
and
342 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// Copyright 2020 Twitter, Inc. | ||
// Licensed under the Apache License, Version 2.0 | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
use crate::units::*; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// constants to define default values | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
// log to the file path | ||
const FILE: Option<String> = None; | ||
|
||
// log will rotate to the given backup path | ||
const BACKUP: Option<String> = None; | ||
|
||
// flush interval in milliseconds | ||
const INTERVAL: usize = 100; | ||
|
||
// max log size before rotate in bytes | ||
const MAX_SIZE: u64 = GB as u64; | ||
|
||
// buffer size in bytes | ||
const NBUF: usize = 0; | ||
|
||
// log 1 in every N commands | ||
const SAMPLE: usize = 100; | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// helper functions | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
fn file() -> Option<String> { | ||
FILE | ||
} | ||
|
||
fn backup() -> Option<String> { | ||
BACKUP | ||
} | ||
|
||
fn interval() -> usize { | ||
INTERVAL | ||
} | ||
|
||
fn max_size() -> u64 { | ||
MAX_SIZE | ||
} | ||
|
||
fn nbuf() -> usize { | ||
NBUF | ||
} | ||
|
||
fn sample() -> usize { | ||
SAMPLE | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// struct definitions | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
pub struct KlogConfig { | ||
#[serde(default = "file")] | ||
file: Option<String>, | ||
#[serde(default = "backup")] | ||
backup: Option<String>, | ||
#[serde(default = "interval")] | ||
interval: usize, | ||
#[serde(default = "nbuf")] | ||
nbuf: usize, | ||
#[serde(default = "sample")] | ||
sample: usize, | ||
#[serde(default = "max_size")] | ||
max_size: u64, | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// implementation | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
impl KlogConfig { | ||
pub fn file(&self) -> Option<String> { | ||
self.file.clone() | ||
} | ||
|
||
pub fn backup(&self) -> Option<String> { | ||
match &self.backup { | ||
Some(path) => Some(path.clone()), | ||
None => self.file.as_ref().map(|path| format!("{}.old", path)), | ||
} | ||
} | ||
|
||
pub fn interval(&self) -> usize { | ||
self.interval | ||
} | ||
|
||
pub fn max_size(&self) -> u64 { | ||
self.max_size | ||
} | ||
|
||
pub fn nbuf(&self) -> usize { | ||
self.nbuf | ||
} | ||
|
||
pub fn sample(&self) -> usize { | ||
self.sample | ||
} | ||
} | ||
|
||
// trait implementations | ||
impl Default for KlogConfig { | ||
fn default() -> Self { | ||
Self { | ||
file: file(), | ||
backup: backup(), | ||
interval: interval(), | ||
max_size: max_size(), | ||
nbuf: nbuf(), | ||
sample: sample(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pub const B: usize = 1; | ||
pub const KB: usize = 1024 * B; | ||
pub const MB: usize = 1024 * KB; | ||
pub const GB: usize = 1024 * MB; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.