In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of how to use sled, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to use sled. Let's take a look at it.
Brief introduction
Sled is an embedded KV database based on Bw tree, and its API is close to a thread-safe BTreeMap. The data structure of its Bw tree, coupled with the "GC" technology including crossbeam-epoch, makes Sled a lock-free database and stands out in the concurrent environment. Forget the slow locks, but officials claim that on a 16-core machine, you can do up to 1 billion operations per minute on a small data set (95% read core 5% write) to use sled, just add sled = "0.32" to the Cargo.toml example basic usage to open the database let tree = sled::open ("/ tmp/welcome-to-sled"). Expect ("open")
/ / insert KV and read the corresponding value of Key tree.insert ("KEY1", "VAL1"); assert_eq! (tree.get (& "KEY1"), Ok (Some (sled::IVec::from ("VAL1")
/ / scope query for kv in tree.range ("KEY1".. "KEY9") {.}
/ / Delete tree.remove (& "KEY1")
/ / atomic compare and swap, which can be used in concurrent programming with tree.compare_and_swap ("KEY1", Some ("VAL1"), Some ("VAL2"))
/ / Block until all modifications are written to the hard disk tree.flush (); process structure use {byteorder:: {BigEndian, LittleEndian}, zerocopy:: {byteorder::U64, AsBytes, FromBytes, LayoutVerified, Unaligned,},}
/ / key structure / / zerocopy::byteorder::U64 ensures data alignment # [derive (FromBytes, AsBytes, Unaligned)] # [repr (C)] struct Key {a: U64, b: U64,}
/ / value structure # [derive (FromBytes, AsBytes, Unaligned)] # [repr (C)] struct Value {count: U64, whatever: [U8; 16],}
Let key = Key {a: U64::new (21), b: U64::new (21)}
/ / get the value corresponding to the key and apply the given function to do db.update_and_fetch (key.as_bytes (), | value_opt | {if let Some (existing) = value_opt {let mut backing_bytes = sled::IVec::from (existing))
/ / verify data alignment (this is not really necessary because we used U64) let layout: LayoutVerified = LayoutVerified::new_unaligned (& mut * backing_bytes) .alignment ("bytes do not fit schema")
/ / get a variable reference to the underlying data let value: & mut Value = layout.into_mut ()
Let new_count = value.count.get () + 1
Println! ("incrementing count to {}", new_count)
Value.count.set (new_count)
Some (backing_bytes)} else {println! ("setting count to 0")
/ / initialize a Value Some (sled::IVec::from (Value {count: U64::new (0), whatever: [0; 16]}. As_bytes (),)})?; that's all for the article "how to use sled". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to use sled". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.