From 4443375019e9a3cf30d5c52fc93cb012a544e5d6 Mon Sep 17 00:00:00 2001 From: terkwood <38859656+Terkwood@users.noreply.github.com> Date: Sat, 11 Apr 2020 18:21:58 -0400 Subject: [PATCH 1/8] Update micro-changelog --- micro-changelog/Cargo.lock | 106 ++++++++++++++++++- micro-changelog/Cargo.toml | 4 +- micro-changelog/Dockerfile | 9 +- micro-changelog/dev-cp.sh | 4 + micro-changelog/src/lib.rs | 7 +- micro-changelog/src/main.rs | 10 +- micro-changelog/src/repo/game_states_repo.rs | 8 +- micro-changelog/src/stream/mod.rs | 79 +++++++------- micro-changelog/src/stream/xread.rs | 7 +- 9 files changed, 181 insertions(+), 53 deletions(-) create mode 100755 micro-changelog/dev-cp.sh diff --git a/micro-changelog/Cargo.lock b/micro-changelog/Cargo.lock index acafd1edf..f994120b0 100644 --- a/micro-changelog/Cargo.lock +++ b/micro-changelog/Cargo.lock @@ -1,11 +1,31 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "aho-corasick" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada" +dependencies = [ + "memchr", +] + [[package]] name = "ascii" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e" +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi 0.3.8", +] + [[package]] name = "bincode" version = "1.2.1" @@ -83,6 +103,19 @@ version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" +[[package]] +name = "env_logger" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + [[package]] name = "fnv" version = "1.0.6" @@ -158,6 +191,24 @@ dependencies = [ "wasi", ] +[[package]] +name = "hermit-abi" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "725cf19794cf90aa94e65050cb4191ff5d8fa87a498383774c47b332e3af952e" +dependencies = [ + "libc", +] + +[[package]] +name = "humantime" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error", +] + [[package]] name = "idna" version = "0.2.0" @@ -238,9 +289,11 @@ checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" [[package]] name = "micro_changelog" -version = "0.1.1" +version = "0.1.2" dependencies = [ "bincode", + "env_logger", + "log", "micro_model_moves", "redis_conn_pool", "redis_streams", @@ -368,6 +421,12 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + [[package]] name = "quote" version = "1.0.2" @@ -482,6 +541,24 @@ version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" +[[package]] +name = "regex" +version = "1.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6946991529684867e47d86474e3a6d0c0ab9b82d5821e314b1ede31fa3a4b3" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", +] + +[[package]] +name = "regex-syntax" +version = "0.6.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae" + [[package]] name = "scheduled-thread-pool" version = "0.2.3" @@ -546,6 +623,24 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "termcolor" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thread_local" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" +dependencies = [ + "lazy_static", +] + [[package]] name = "tokio" version = "0.2.12" @@ -672,6 +767,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa515c5163a99cc82bab70fd3bfdd36d827be85de63737b40fcef2ce084a436e" +dependencies = [ + "winapi 0.3.8", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/micro-changelog/Cargo.toml b/micro-changelog/Cargo.toml index 926fffa75..7f3e38aed 100644 --- a/micro-changelog/Cargo.toml +++ b/micro-changelog/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "micro_changelog" -version = "0.1.1" +version = "0.1.2" authors = ["terkwood <38859656+Terkwood@users.noreply.github.com>"] edition = "2018" @@ -11,3 +11,5 @@ redis_conn_pool = { git = "https://github.com/Terkwood/BUGOUT", branch = "unstab redis_streams = { git = "https://github.com/Terkwood/BUGOUT", branch = "unstable" } bincode = "1.2.1" uuid = { version = "0.8.1", features = ["serde"] } +log = "0.4.8" +env_logger = "0.7.1" diff --git a/micro-changelog/Dockerfile b/micro-changelog/Dockerfile index 4d6644b19..e4271c6ea 100644 --- a/micro-changelog/Dockerfile +++ b/micro-changelog/Dockerfile @@ -6,6 +6,11 @@ RUN rustup default stable COPY . /var/BUGOUT/micro-changelog/. -RUN cargo install --path . +#TODO +#RUN cargo install --path . -CMD ["micro_changelog"] +ENV RUST_LOG info + +#TODO +#CMD ["micro_changelog"] +CMD [ "tail","-f","/dev/null"] diff --git a/micro-changelog/dev-cp.sh b/micro-changelog/dev-cp.sh new file mode 100755 index 000000000..3d006d219 --- /dev/null +++ b/micro-changelog/dev-cp.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +docker cp Cargo.toml bugout_micro-changelog_1:/var/BUGOUT/micro-changelog/. +docker cp src bugout_micro-changelog_1:/var/BUGOUT/micro-changelog/. diff --git a/micro-changelog/src/lib.rs b/micro-changelog/src/lib.rs index 6e6c50fd3..7c148f7c9 100644 --- a/micro-changelog/src/lib.rs +++ b/micro-changelog/src/lib.rs @@ -1,6 +1,9 @@ extern crate bincode; +extern crate env_logger; +extern crate log; pub extern crate micro_model_moves; extern crate redis_streams; + mod model; pub mod repo; pub mod stream; @@ -9,6 +12,8 @@ pub use redis_conn_pool; pub use redis_conn_pool::{r2d2, r2d2_redis, redis, RedisHostUrl}; use repo::redis_key::KeyProvider; +use log::info; + pub struct Components { pub pool: redis_conn_pool::Pool, pub redis_key_provider: KeyProvider, @@ -17,7 +22,7 @@ pub struct Components { impl Default for Components { fn default() -> Self { let pool = redis_conn_pool::create(RedisHostUrl::default()); - println!("Connected to redis"); + info!("Connected to redis"); Components { pool, redis_key_provider: KeyProvider::default(), diff --git a/micro-changelog/src/main.rs b/micro-changelog/src/main.rs index f2189bee3..98d955198 100644 --- a/micro-changelog/src/main.rs +++ b/micro-changelog/src/main.rs @@ -1,11 +1,13 @@ -const NAME: &'static str = env!("CARGO_PKG_NAME"); -const VERSION: &'static str = env!("CARGO_PKG_VERSION"); - use micro_changelog::stream; use micro_changelog::Components; use stream::StreamTopics; +use log::info; + +const VERSION: &'static str = env!("CARGO_PKG_VERSION"); + fn main() { - println!("🔢 {:<8} {}", NAME, VERSION); + env_logger::init(); + info!("🔢 {}", VERSION); stream::process(StreamTopics::default(), &Components::default()) } diff --git a/micro-changelog/src/repo/game_states_repo.rs b/micro-changelog/src/repo/game_states_repo.rs index 14a55c34f..0c353d737 100644 --- a/micro-changelog/src/repo/game_states_repo.rs +++ b/micro-changelog/src/repo/game_states_repo.rs @@ -21,16 +21,16 @@ pub fn fetch(game_id: &GameId, components: &Components) -> Result Result { +) -> Result { let mut conn = components.pool.get().unwrap(); - let key = components.redis_key_provider.game_states(&game_id); + let key = components.redis_key_provider.game_states(game_id); let done = conn.set(&key, game_state.serialize()?)?; // Touch TTL whenever you set the record conn.expire(key, EXPIRY_SECS)?; - + Ok(done) } diff --git a/micro-changelog/src/stream/mod.rs b/micro-changelog/src/stream/mod.rs index 12228c867..534e29f0e 100644 --- a/micro-changelog/src/stream/mod.rs +++ b/micro-changelog/src/stream/mod.rs @@ -8,8 +8,11 @@ use micro_model_moves::*; use redis_conn_pool::redis; pub use topics::StreamTopics; use xread::*; + +use log::{error, info}; + pub fn process(topics: StreamTopics, components: &crate::Components) { - println!("Processing {:#?}", topics); + info!("Processing {:#?}", topics); loop { match entry_id_repo::fetch_all(components) { Ok(entry_ids) => match xread_sorted(entry_ids, &topics, &components.pool) { @@ -18,58 +21,59 @@ pub fn process(topics: StreamTopics, components: &crate::Components) { match time_ordered_event { (entry_id, StreamData::MA(move_acc)) => { match update_game_state(&move_acc, &components) { - Err(e) => println!("err updating game state {:?}", e), + Err(e) => error!("err updating game state {:?}", e), Ok(gs) => { + // These next two ops are concurrent in the kafka impl + if let Err(e) = xadd_game_states_changelog( + &move_acc.game_id, + gs, + &topics.game_states_changelog, + components, + ) { + error!("could not XADD to game state changelog {:?}", e) + } + if let Err(e) = xadd_move_made( &move_acc, &topics.move_made_ev, &components, - ) - .and_then(|_| { - xadd_game_states_changelog( - &move_acc.game_id, - gs, - &topics.game_states_changelog, - components, - ) - }) { - println!("err in XADDs {:?}", e) - } else { - if let Err(e) = entry_id_repo::update( - EntryIdType::MoveAcceptedEvent, - entry_id, - &components, - ) { - println!( - "err saving entry id for move accepted {:?}", - e - ) - } + ) { + error!("err in XADD move made {:?}", e) + } + + if let Err(e) = entry_id_repo::update( + EntryIdType::MoveAcceptedEvent, + entry_id, + &components, + ) { + error!("err saving entry id for move accepted {:?}", e) } } } } (entry_id, StreamData::GS(game_id, gs)) => { - if let Err(e) = game_states_repo::write(game_id, &gs, &components) { - println!("Error saving game state {:#?}", e) + if let Err(e) = game_states_repo::write(&game_id, &gs, &components) + { + error!("Error saving game state {:#?}", e) } else { - println!("loop game STATE"); - if let Err(e) = entry_id_repo::update( - EntryIdType::GameStateChangelog, - entry_id, - &components, - ) { - println!("Error saving entry ID for game state {:#?}", e) - } + info!("wrote game state: {:?} {:?}", game_id, gs); + } + + if let Err(e) = entry_id_repo::update( + EntryIdType::GameStateChangelog, + entry_id, + &components, + ) { + error!("Error saving entry ID for game state {:#?}", e) } } } } } - Err(e) => println!("Redis err in xread: {:#?}", e), + Err(e) => error!("Redis err in xread: {:#?}", e), }, - Err(FetchErr::Deser) => println!("Unable to deserialize entry IDs"), - Err(FetchErr::Redis(r)) => println!("Redis err {:#?}", r), + Err(FetchErr::Deser) => error!("Unable to deserialize entry IDs"), + Err(FetchErr::Redis(r)) => error!("Redis err {:#?}", r), } } } @@ -102,7 +106,7 @@ fn update_game_state( og.moves.push(move_acc.clone()); og })?; - game_states_repo::write(game_id, &new_game_state, &components)?; + game_states_repo::write(&game_id, &new_game_state, &components)?; Ok(new_game_state) } @@ -148,6 +152,7 @@ fn xadd_game_states_changelog( components: &Components, ) -> Result { let mut conn = components.pool.get().unwrap(); + info!("Must XADD game state: {:?}", gs); Ok(redis::cmd("XADD") .arg(stream_name) .arg("MAXLEN") diff --git a/micro-changelog/src/stream/xread.rs b/micro-changelog/src/stream/xread.rs index c17656ad5..a09201e37 100644 --- a/micro-changelog/src/stream/xread.rs +++ b/micro-changelog/src/stream/xread.rs @@ -1,6 +1,7 @@ use super::StreamTopics; use crate::redis; use crate::repo::entry_id_repo::AllEntryIds; +use log::{error, warn}; use micro_model_moves::{GameId, GameState, MoveMade}; use redis_conn_pool::Pool; use redis_streams::XReadEntryId; @@ -67,7 +68,7 @@ fn deser(xread_result: XReadResult, topics: &StreamTopics) -> HashMap HashMap Date: Sat, 11 Apr 2020 18:22:08 -0400 Subject: [PATCH 2/8] Update micro-judge --- micro-judge/Cargo.lock | 165 ++++++++++++++++++++++------ micro-judge/Cargo.toml | 4 +- micro-judge/Dockerfile | 10 +- micro-judge/src/game/mod.rs | 3 + micro-judge/src/io/stream.rs | 90 +++++++++------ micro-judge/src/io/xread.rs | 47 +++++--- micro-judge/src/lib.rs | 2 + micro-judge/src/main.rs | 6 +- micro-judge/src/repo/entry_id.rs | 7 ++ micro-judge/src/repo/game_states.rs | 17 ++- 10 files changed, 258 insertions(+), 93 deletions(-) diff --git a/micro-judge/Cargo.lock b/micro-judge/Cargo.lock index 6a3aed8ae..b4e1a1c0b 100644 --- a/micro-judge/Cargo.lock +++ b/micro-judge/Cargo.lock @@ -1,11 +1,31 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "aho-corasick" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada" +dependencies = [ + "memchr", +] + [[package]] name = "ascii" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e" +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi 0.3.8", +] + [[package]] name = "bincode" version = "1.2.1" @@ -34,15 +54,6 @@ version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "130aac562c0dd69c56b3b1cc8ffd2e17be31d0b6c25b61c96b76231aa23e39e1" -[[package]] -name = "c2-chacha" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb" -dependencies = [ - "ppv-lite86", -] - [[package]] name = "cfg-if" version = "0.1.10" @@ -83,6 +94,19 @@ version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" +[[package]] +name = "env_logger" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + [[package]] name = "fnv" version = "1.0.6" @@ -158,6 +182,24 @@ dependencies = [ "wasi", ] +[[package]] +name = "hermit-abi" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "725cf19794cf90aa94e65050cb4191ff5d8fa87a498383774c47b332e3af952e" +dependencies = [ + "libc", +] + +[[package]] +name = "humantime" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error", +] + [[package]] name = "idna" version = "0.2.0" @@ -202,9 +244,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.66" +version = "0.2.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" +checksum = "dea0c0405123bba743ee3f91f49b1c7cfb684eef0da0a50110f758ccf24cdff0" [[package]] name = "lock_api" @@ -232,15 +274,17 @@ checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" [[package]] name = "memchr" -version = "2.3.2" +version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53445de381a1f436797497c61d851644d0e8e88e6140f22872ad33a704933978" +checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" [[package]] name = "micro_judge" -version = "0.1.6" +version = "0.1.7" dependencies = [ "bincode", + "env_logger", + "log", "micro_model_moves", "redis_conn_pool", "redis_streams", @@ -249,8 +293,8 @@ dependencies = [ [[package]] name = "micro_model_moves" -version = "0.1.1" -source = "git+https://github.com/Terkwood/BUGOUT?branch=unstable#94af2e2b542059dab45240f1066409b0446d513f" +version = "0.1.2" +source = "git+https://github.com/Terkwood/BUGOUT?branch=unstable#574ac7d43cc4f5fc3d8d3ab0cff81df1c57a2c75" dependencies = [ "bincode", "serde", @@ -361,18 +405,24 @@ checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" [[package]] name = "proc-macro2" -version = "1.0.8" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acb317c6ff86a4e579dfa00fc5e6cca91ecbb4e7eb2df0468805b674eb88548" +checksum = "df246d292ff63439fea9bc8c0a270bed0e390d5ebd4db4ba15aba81111b5abe3" dependencies = [ "unicode-xid", ] +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + [[package]] name = "quote" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" +checksum = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f" dependencies = [ "proc-macro2", ] @@ -413,11 +463,11 @@ dependencies = [ [[package]] name = "rand_chacha" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ - "c2-chacha", + "ppv-lite86", "rand_core", ] @@ -462,7 +512,7 @@ dependencies = [ [[package]] name = "redis_conn_pool" version = "0.1.0" -source = "git+https://github.com/Terkwood/BUGOUT?branch=unstable#94af2e2b542059dab45240f1066409b0446d513f" +source = "git+https://github.com/Terkwood/BUGOUT?branch=unstable#574ac7d43cc4f5fc3d8d3ab0cff81df1c57a2c75" dependencies = [ "r2d2_redis", "redis", @@ -471,7 +521,7 @@ dependencies = [ [[package]] name = "redis_streams" version = "0.1.0" -source = "git+https://github.com/Terkwood/BUGOUT?branch=unstable#94af2e2b542059dab45240f1066409b0446d513f" +source = "git+https://github.com/Terkwood/BUGOUT?branch=unstable#574ac7d43cc4f5fc3d8d3ab0cff81df1c57a2c75" dependencies = [ "uuid", ] @@ -482,11 +532,29 @@ version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" +[[package]] +name = "regex" +version = "1.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6946991529684867e47d86474e3a6d0c0ab9b82d5821e314b1ede31fa3a4b3" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", +] + +[[package]] +name = "regex-syntax" +version = "0.6.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae" + [[package]] name = "scheduled-thread-pool" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5de7bc31f28f8e6c28df5e1bf3d10610f5fdc14cc95f272853512c70a2bd779" +checksum = "0988d7fdf88d5e5fcf5923a0f1e8ab345f3e98ab4bc6bc45a2d5ff7f7458fbf6" dependencies = [ "parking_lot", ] @@ -499,18 +567,18 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.104" +version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" +checksum = "36df6ac6412072f67cf767ebbde4133a5b2e88e76dc6187fa7104cd16f783399" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.104" +version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" +checksum = "9e549e3abf4fb8621bd1609f11dfc9f5e50320802273b12f3811a67e6716ea6c" dependencies = [ "proc-macro2", "quote", @@ -537,20 +605,38 @@ checksum = "5c2fb2ec9bcd216a5b0d0ccf31ab17b5ed1d627960edff65bbe95d3ce221cefc" [[package]] name = "syn" -version = "1.0.15" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a0294dc449adc58bb6592fff1a23d3e5e6e235afc6a0ffca2657d19e7bbffe5" +checksum = "0df0eb663f387145cab623dea85b09c2c5b4b0aef44e945d928e682fce71bb03" dependencies = [ "proc-macro2", "quote", "unicode-xid", ] +[[package]] +name = "termcolor" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thread_local" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" +dependencies = [ + "lazy_static", +] + [[package]] name = "tokio" -version = "0.2.11" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fdd17989496f49cdc57978c96f0c9fe5e4a58a8bddc6813c449a4624f6a030b" +checksum = "ee5a0dd887e37d37390c13ff8ac830f992307fe30a1fff0ab8427af67211ba28" dependencies = [ "bytes", "fnv", @@ -672,6 +758,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa515c5163a99cc82bab70fd3bfdd36d827be85de63737b40fcef2ce084a436e" +dependencies = [ + "winapi 0.3.8", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/micro-judge/Cargo.toml b/micro-judge/Cargo.toml index 0b9ff6d5f..340b29044 100644 --- a/micro-judge/Cargo.toml +++ b/micro-judge/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "micro_judge" -version = "0.1.6" +version = "0.1.7" authors = ["terkwood <38859656+Terkwood@users.noreply.github.com>"] edition = "2018" @@ -10,3 +10,5 @@ bincode = "1.2.1" micro_model_moves = { git = "https://github.com/Terkwood/BUGOUT", branch = "unstable" } redis_conn_pool = { git = "https://github.com/Terkwood/BUGOUT", branch = "unstable" } redis_streams = {git = "https://github.com/Terkwood/BUGOUT", branch = "unstable"} +env_logger = "0.7.1" +log = "0.4.8" diff --git a/micro-judge/Dockerfile b/micro-judge/Dockerfile index 1fb97d662..fa4e08b72 100644 --- a/micro-judge/Dockerfile +++ b/micro-judge/Dockerfile @@ -6,6 +6,12 @@ RUN rustup default stable COPY . /var/BUGOUT/micro-judge/. -RUN cargo install --path . +#TODO +#RUN cargo install --path . -CMD ["micro_judge"] +ENV RUST_LOG info + +# TODO +#CMD ["micro_judge"] + +CMD [ "tail", "-f", "/dev/null" ] diff --git a/micro-judge/src/game/mod.rs b/micro-judge/src/game/mod.rs index d8fe33ef6..8077bf617 100644 --- a/micro-judge/src/game/mod.rs +++ b/micro-judge/src/game/mod.rs @@ -1,6 +1,8 @@ use crate::model::*; pub use capturing::captures_for; +use log::info; + mod capturing; pub enum Judgement { @@ -8,6 +10,7 @@ pub enum Judgement { Rejected, } pub fn judge(mm: &MakeMoveCommand, game_state: &GameState) -> Judgement { + info!("Judge {:?}", mm); if validate_move(mm, game_state) { let captured: Vec = mm .coord diff --git a/micro-judge/src/io/stream.rs b/micro-judge/src/io/stream.rs index 993031017..393ee32ae 100644 --- a/micro-judge/src/io/stream.rs +++ b/micro-judge/src/io/stream.rs @@ -8,58 +8,83 @@ use crate::model::*; use crate::repo::entry_id::{EntryIdRepo, EntryIdType}; use crate::repo::game_states::GameStatesRepo; +use log::{error, info, warn}; + pub fn process(opts: ProcessOpts, pool: &Pool) { let eid_repo = opts.entry_id_repo; + + let mut _last_err_count: u64 = 0; // TODO + let mut _err_count: u64 = 0; // TODO + + // You know what? This spins. TODO loop { match eid_repo.fetch_all() { Ok(entry_ids) => { - if let Ok(xread_result) = xread_sort(entry_ids, &opts.topics, &pool) { + if let Ok(xread_result) = xread_sort(&entry_ids, &opts.topics, &pool) { for time_ordered_event in xread_result { + info!("EIDS {:?}", entry_ids); match time_ordered_event { (entry_id, StreamData::MM(mm)) => { - match make_move(&mm, &opts.game_states_repo) { - Err(e) => println!("Fetch err on game state {:#?}", e), - Ok(Judgement::Accepted(move_made)) => { - if let Err(e) = xadd_move_accepted( - &move_made, - &pool, - &opts.topics.move_accepted_ev, - ) { - println!("Error XADD to move_accepted {:?}", e) - } else { - if let Err(e) = eid_repo - .update(EntryIdType::MakeMoveCommand, entry_id) - { - println!( - "error updating make_move_cmd eid: {:?}", - e - ) + let fetched_gs = opts.game_states_repo.fetch(&mm.game_id); + match fetched_gs { + Ok(Some(game_state)) => match judge(&mm, &game_state) { + Judgement::Accepted(move_made) => { + if let Err(e) = xadd_move_accepted( + &move_made, + &pool, + &opts.topics.move_accepted_ev, + ) { + error!("Error XADD to move_accepted {:?}", e) } } - } - Ok(Judgement::Rejected) => println!("MOVE REJECTED: {:#?}", mm), + Judgement::Rejected => { + //err_count += 1; // TODO + error!("MOVE REJECTED: {:#?}", mm) + } + }, + Ok(None) => warn!("No game state for game {}", mm.game_id.0), + Err(e) => error!("Deser error ({:?})!", e), + } + + if let Err(e) = + eid_repo.update(EntryIdType::MakeMoveCommand, entry_id) + { + error!("error updating make_move_cmd eid: {:?}", e) } } (entry_id, StreamData::GS(game_id, game_state)) => { - if let Err(e) = &opts.game_states_repo.write(game_id, game_state) { - println!("error writing game state {:?}", e) - } else { - if let Err(e) = - eid_repo.update(EntryIdType::GameStateChangelog, entry_id) - { - println!("error updating changelog eid: {:?}", e); - } + if let Err(e) = &opts.game_states_repo.write(&game_id, &game_state) + { + error!( + "error writing game state {:?} -- advancing eid pointer", + e + ) } + + if let Err(e) = + eid_repo.update(EntryIdType::GameStateChangelog, entry_id) + { + error!("error updating changelog eid: {:?}", e); + } + + info!("Tracking {:?} {:?}", game_id, game_state); } } } } } - Err(FetchErr::Deser) => println!("Deserialization err in stream processing"), - Err(FetchErr::Redis(r)) => println!("Redis error in stream processing {:?}", r), + Err(FetchErr::Deser) => error!("Deserialization err in stream processing"), + Err(FetchErr::Redis(r)) => error!("Redis error in stream processing {:?}", r), } + + // TODO + /*if err_count % 100 == 0 && err_count != last_err_count { + last_err_count = err_count; + error!("Err count: {}", err_count); + }*/ } } + #[derive(Clone)] pub struct ProcessOpts { pub topics: StreamTopics, @@ -81,11 +106,6 @@ impl Default for ProcessOpts { } } -fn make_move(mm: &MakeMoveCommand, gs_repo: &GameStatesRepo) -> Result { - let game_state = gs_repo.fetch(&mm.game_id)?; - Ok(judge(mm, &game_state)) -} - fn xadd_move_accepted( move_made: &MoveMade, pool: &Pool, diff --git a/micro-judge/src/io/xread.rs b/micro-judge/src/io/xread.rs index ff80caddc..169c6cdae 100644 --- a/micro-judge/src/io/xread.rs +++ b/micro-judge/src/io/xread.rs @@ -3,16 +3,17 @@ use super::redis; use super::topics::*; use crate::model::*; use crate::repo::entry_id::AllEntryIds; +use log::{error, info}; use redis_streams::*; use std::collections::HashMap; use std::str::FromStr; use uuid::Uuid; const BLOCK_MSEC: u32 = 5000; -pub type XReadResult = Vec>>>>; +pub type XReadResult = Vec>>>>>; pub fn xread_sort( - entry_ids: AllEntryIds, + entry_ids: &AllEntryIds, topics: &StreamTopics, pool: &Pool, ) -> Result, redis::RedisError> { @@ -30,6 +31,7 @@ pub fn xread_sort( let unsorted = deser(ser, &topics); let mut sorted_keys: Vec = unsorted.keys().map(|k| *k).collect(); sorted_keys.sort(); + let skc = sorted_keys.clone(); let mut answer = vec![]; for sk in sorted_keys { @@ -37,6 +39,20 @@ pub fn xread_sort( answer.push((sk, data.clone())) } } + + if !unsorted.is_empty() || !skc.is_empty() || !answer.is_empty() { + info!( + "MM_EID {} GS_EID {}", + entry_ids.make_moves_eid.to_string(), + entry_ids.game_states_eid.to_string() + ); + info!( + "Unsorted {} Sorted_keys {} answer {}", + unsorted.len(), + skc.len(), + answer.len() + ); + } Ok(answer) } @@ -60,7 +76,7 @@ fn deser(xread_result: XReadResult, topics: &StreamTopics) -> HashMap HashMap HashMap, + xread_result: HashMap>, ) -> Result { - let mx: Option = xread_result + let values_as_strings: HashMap = xread_result + .iter() + .map(|(k, v)| (k.clone(), String::from_utf8(v.clone()).expect("bytes"))) + .collect(); + let mx: Option = values_as_strings .get("coord_x") .and_then(|s| s.parse::().ok()); - let my: Option = xread_result + let my: Option = values_as_strings .get("coord_y") .and_then(|s| s.parse::().ok()); let coord = match (mx, my) { @@ -102,9 +123,9 @@ fn deser_make_move_command( _ => None, }; Ok(MakeMoveCommand { - game_id: GameId(Uuid::from_str(&xread_result["game_id"])?), - req_id: ReqId(Uuid::from_str(&xread_result["req_id"])?), - player: Player::from_str(&xread_result["player"]), + game_id: GameId(Uuid::from_str(&values_as_strings["game_id"])?), + req_id: ReqId(Uuid::from_str(&values_as_strings["req_id"])?), + player: Player::from_str(&values_as_strings["player"]), coord, }) } diff --git a/micro-judge/src/lib.rs b/micro-judge/src/lib.rs index d3e9cbca8..97c8c0d5e 100644 --- a/micro-judge/src/lib.rs +++ b/micro-judge/src/lib.rs @@ -1,3 +1,5 @@ +extern crate env_logger; +extern crate log; extern crate micro_model_moves; pub extern crate redis_conn_pool; extern crate redis_streams; diff --git a/micro-judge/src/main.rs b/micro-judge/src/main.rs index 5447a37bd..75b1fc656 100644 --- a/micro-judge/src/main.rs +++ b/micro-judge/src/main.rs @@ -1,12 +1,16 @@ +extern crate log; extern crate micro_judge; +use log::info; + use micro_judge::io::{conn_pool, stream}; const NAME: &'static str = env!("CARGO_PKG_NAME"); const VERSION: &'static str = env!("CARGO_PKG_VERSION"); fn main() { - println!("🔢 {:<8} {}", NAME, VERSION); + env_logger::init(); + info!("🔢 {:<8} {}", NAME, VERSION); stream::process( stream::ProcessOpts::default(), &conn_pool::create(conn_pool::RedisHostUrl::default()), diff --git a/micro-judge/src/repo/entry_id.rs b/micro-judge/src/repo/entry_id.rs index 5365c3e9a..22ea4e32e 100644 --- a/micro-judge/src/repo/entry_id.rs +++ b/micro-judge/src/repo/entry_id.rs @@ -4,6 +4,7 @@ use io::r2d2_redis::redis; use io::redis::Commands; use io::redis_keys::*; use io::FetchErr; +use log::info; use redis_streams::XReadEntryId; use std::collections::HashMap; @@ -46,6 +47,12 @@ impl EntryIdRepo { entry_id: XReadEntryId, ) -> Result<(), redis::RedisError> { let mut conn = self.pool.get().unwrap(); + info!( + "Update {} {} {} ", + entry_ids_hash_key(&self.namespace), + entry_id_type.hash_field(), + entry_id.to_string() + ); conn.hset( entry_ids_hash_key(&self.namespace), entry_id_type.hash_field(), diff --git a/micro-judge/src/repo/game_states.rs b/micro-judge/src/repo/game_states.rs index 5ffce5e87..de454ffba 100644 --- a/micro-judge/src/repo/game_states.rs +++ b/micro-judge/src/repo/game_states.rs @@ -14,17 +14,22 @@ pub struct GameStatesRepo { } impl GameStatesRepo { - pub fn fetch(&self, game_id: &GameId) -> Result { + pub fn fetch(&self, game_id: &GameId) -> Result, FetchErr> { let mut conn = self.pool.get().unwrap(); let key = game_states_key(&self.namespace, &game_id); - let bin_data: Vec = conn.get(&key)?; - let r = GameState::from(&bin_data)?; - // Touch TTL whenever you get the record - conn.expire(key, EXPIRY_SECS)?; + let bin_data: Option> = conn.get(&key)?; + let r = if let Some(b) = bin_data { + // Touch TTL whenever you get the record + conn.expire(key, EXPIRY_SECS)?; + Some(GameState::from(&b)?) + } else { + None + }; + Ok(r) } - pub fn write(&self, game_id: GameId, game_state: GameState) -> Result { + pub fn write(&self, game_id: &GameId, game_state: &GameState) -> Result { let mut conn = self.pool.get().unwrap(); let key = game_states_key(&self.namespace, &game_id); From 160ea66a9206c368fc2651af4bc68b26e2555ef4 Mon Sep 17 00:00:00 2001 From: terkwood <38859656+Terkwood@users.noreply.github.com> Date: Sat, 11 Apr 2020 18:22:50 -0400 Subject: [PATCH 3/8] Fix dockerfiles --- micro-changelog/Dockerfile | 7 ++----- micro-judge/Dockerfile | 8 ++------ 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/micro-changelog/Dockerfile b/micro-changelog/Dockerfile index e4271c6ea..1bec32b7a 100644 --- a/micro-changelog/Dockerfile +++ b/micro-changelog/Dockerfile @@ -6,11 +6,8 @@ RUN rustup default stable COPY . /var/BUGOUT/micro-changelog/. -#TODO -#RUN cargo install --path . +RUN cargo install --path . ENV RUST_LOG info -#TODO -#CMD ["micro_changelog"] -CMD [ "tail","-f","/dev/null"] +CMD ["micro_changelog"] diff --git a/micro-judge/Dockerfile b/micro-judge/Dockerfile index fa4e08b72..16f1f4d30 100644 --- a/micro-judge/Dockerfile +++ b/micro-judge/Dockerfile @@ -6,12 +6,8 @@ RUN rustup default stable COPY . /var/BUGOUT/micro-judge/. -#TODO -#RUN cargo install --path . +RUN cargo install --path . ENV RUST_LOG info -# TODO -#CMD ["micro_judge"] - -CMD [ "tail", "-f", "/dev/null" ] +CMD ["micro_judge"] From 9316f49cf8a935fc2d2a94f2c65714ffee848e8b Mon Sep 17 00:00:00 2001 From: terkwood <38859656+Terkwood@users.noreply.github.com> Date: Sat, 11 Apr 2020 19:45:33 -0400 Subject: [PATCH 4/8] Trim and raise issue --- micro-judge/src/io/stream.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/micro-judge/src/io/stream.rs b/micro-judge/src/io/stream.rs index 393ee32ae..2317f75fa 100644 --- a/micro-judge/src/io/stream.rs +++ b/micro-judge/src/io/stream.rs @@ -10,13 +10,10 @@ use crate::repo::game_states::GameStatesRepo; use log::{error, info, warn}; +/// Spins too much. See https://github.com/Terkwood/BUGOUT/issues/217 pub fn process(opts: ProcessOpts, pool: &Pool) { let eid_repo = opts.entry_id_repo; - let mut _last_err_count: u64 = 0; // TODO - let mut _err_count: u64 = 0; // TODO - - // You know what? This spins. TODO loop { match eid_repo.fetch_all() { Ok(entry_ids) => { @@ -76,12 +73,6 @@ pub fn process(opts: ProcessOpts, pool: &Pool) { Err(FetchErr::Deser) => error!("Deserialization err in stream processing"), Err(FetchErr::Redis(r)) => error!("Redis error in stream processing {:?}", r), } - - // TODO - /*if err_count % 100 == 0 && err_count != last_err_count { - last_err_count = err_count; - error!("Err count: {}", err_count); - }*/ } } From 81c9402974578d7efe88bbd045db615e26a9d6f2 Mon Sep 17 00:00:00 2001 From: terkwood <38859656+Terkwood@users.noreply.github.com> Date: Sat, 11 Apr 2020 19:46:03 -0400 Subject: [PATCH 5/8] Trim --- micro-judge/src/io/stream.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/micro-judge/src/io/stream.rs b/micro-judge/src/io/stream.rs index 2317f75fa..88e70a45d 100644 --- a/micro-judge/src/io/stream.rs +++ b/micro-judge/src/io/stream.rs @@ -35,7 +35,6 @@ pub fn process(opts: ProcessOpts, pool: &Pool) { } } Judgement::Rejected => { - //err_count += 1; // TODO error!("MOVE REJECTED: {:#?}", mm) } }, From 4fe520fa5099cc5754c203fba4a4bcea8a9e6738 Mon Sep 17 00:00:00 2001 From: terkwood <38859656+Terkwood@users.noreply.github.com> Date: Sat, 11 Apr 2020 19:48:00 -0400 Subject: [PATCH 6/8] Trim --- micro-changelog/src/stream/mod.rs | 2 +- micro-judge/src/io/xread.rs | 16 +--------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/micro-changelog/src/stream/mod.rs b/micro-changelog/src/stream/mod.rs index 534e29f0e..8a94b3749 100644 --- a/micro-changelog/src/stream/mod.rs +++ b/micro-changelog/src/stream/mod.rs @@ -31,7 +31,7 @@ pub fn process(topics: StreamTopics, components: &crate::Components) { components, ) { error!("could not XADD to game state changelog {:?}", e) - } + } if let Err(e) = xadd_move_made( &move_acc, diff --git a/micro-judge/src/io/xread.rs b/micro-judge/src/io/xread.rs index 169c6cdae..becd9fd82 100644 --- a/micro-judge/src/io/xread.rs +++ b/micro-judge/src/io/xread.rs @@ -3,7 +3,7 @@ use super::redis; use super::topics::*; use crate::model::*; use crate::repo::entry_id::AllEntryIds; -use log::{error, info}; +use log::error; use redis_streams::*; use std::collections::HashMap; use std::str::FromStr; @@ -31,7 +31,6 @@ pub fn xread_sort( let unsorted = deser(ser, &topics); let mut sorted_keys: Vec = unsorted.keys().map(|k| *k).collect(); sorted_keys.sort(); - let skc = sorted_keys.clone(); let mut answer = vec![]; for sk in sorted_keys { @@ -40,19 +39,6 @@ pub fn xread_sort( } } - if !unsorted.is_empty() || !skc.is_empty() || !answer.is_empty() { - info!( - "MM_EID {} GS_EID {}", - entry_ids.make_moves_eid.to_string(), - entry_ids.game_states_eid.to_string() - ); - info!( - "Unsorted {} Sorted_keys {} answer {}", - unsorted.len(), - skc.len(), - answer.len() - ); - } Ok(answer) } From 176a5f2aeb3ef741ba914162b8debc2a2da04818 Mon Sep 17 00:00:00 2001 From: terkwood <38859656+Terkwood@users.noreply.github.com> Date: Sat, 11 Apr 2020 19:49:24 -0400 Subject: [PATCH 7/8] Trim --- micro-changelog/src/stream/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/micro-changelog/src/stream/mod.rs b/micro-changelog/src/stream/mod.rs index 8a94b3749..ff1a2e09c 100644 --- a/micro-changelog/src/stream/mod.rs +++ b/micro-changelog/src/stream/mod.rs @@ -152,7 +152,6 @@ fn xadd_game_states_changelog( components: &Components, ) -> Result { let mut conn = components.pool.get().unwrap(); - info!("Must XADD game state: {:?}", gs); Ok(redis::cmd("XADD") .arg(stream_name) .arg("MAXLEN") From c92128414d8da51e329d61d476515e6624ba94c1 Mon Sep 17 00:00:00 2001 From: terkwood <38859656+Terkwood@users.noreply.github.com> Date: Sat, 11 Apr 2020 19:51:02 -0400 Subject: [PATCH 8/8] Trim --- micro-judge/src/io/stream.rs | 4 +--- micro-judge/src/repo/entry_id.rs | 9 ++------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/micro-judge/src/io/stream.rs b/micro-judge/src/io/stream.rs index 88e70a45d..4c385b594 100644 --- a/micro-judge/src/io/stream.rs +++ b/micro-judge/src/io/stream.rs @@ -34,9 +34,7 @@ pub fn process(opts: ProcessOpts, pool: &Pool) { error!("Error XADD to move_accepted {:?}", e) } } - Judgement::Rejected => { - error!("MOVE REJECTED: {:#?}", mm) - } + Judgement::Rejected => error!("MOVE REJECTED: {:#?}", mm), }, Ok(None) => warn!("No game state for game {}", mm.game_id.0), Err(e) => error!("Deser error ({:?})!", e), diff --git a/micro-judge/src/repo/entry_id.rs b/micro-judge/src/repo/entry_id.rs index 22ea4e32e..f28dc23e1 100644 --- a/micro-judge/src/repo/entry_id.rs +++ b/micro-judge/src/repo/entry_id.rs @@ -4,7 +4,6 @@ use io::r2d2_redis::redis; use io::redis::Commands; use io::redis_keys::*; use io::FetchErr; -use log::info; use redis_streams::XReadEntryId; use std::collections::HashMap; @@ -17,6 +16,7 @@ pub struct EntryIdRepo { pub namespace: RedisKeyNamespace, pub pool: Pool, } + impl EntryIdRepo { pub fn fetch_all(&self) -> Result { let mut conn = self.pool.get().unwrap(); @@ -47,12 +47,7 @@ impl EntryIdRepo { entry_id: XReadEntryId, ) -> Result<(), redis::RedisError> { let mut conn = self.pool.get().unwrap(); - info!( - "Update {} {} {} ", - entry_ids_hash_key(&self.namespace), - entry_id_type.hash_field(), - entry_id.to_string() - ); + conn.hset( entry_ids_hash_key(&self.namespace), entry_id_type.hash_field(),