In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article shows you what is leveldb, the content is concise and easy to understand, can definitely make your eyes bright, through the detailed introduction of this article, I hope you can get something.
Leveldb is a very efficient kv database implemented by google, created by the famous Jeff Dean and Sanjay Ghemawat, and the current version 1.2 can support data volumes at the billion level. It also has very high performance at this level, mainly due to its good design.
LevelDB is a single-process service with very high performance. On a 4 Q6600 CPU machine, data is written more than 40w per second, while the performance of random reads is more than 10w per second. It has the following functional features:
Key and value can be strings or byte streams
The data is arranged by key and stored in an orderly manner.
Callers can overload sorting methods to implement custom sorting
There are only three basic operations: Put (key, value), Get (key), and Delete (key)
Provides an interface for atomic batch modification.
Support for data snapshots
Support for forward and backward iterators
Supports automatic data compression, using the snappy compression algorithm
External interactions with the operating system are done through virtual interfaces (virtual interface) so that users can customize these interactions
LevelDB is awesome, but the best tool has its limitations, and the limitations of LevelDB are obvious:
This is not an SQL database, it does not have a relational data model, does not support SQL queries, and does not support indexes.
At the same time, only one process (possibly a process with multiple threads) can access a specific database.
The library does not have built-in client-server support, and users who need it must package it themselves.
How to use LevelDB to open a database
The name of the leveldb database corresponds to the file system directory. All the contents of the database are stored in this directory. The following example shows how to open a database:
# include # include "leveldb/db.h" leveldb::DB* db; leveldb::Options options; options.create_if_missing = true; leveldb::Status status = leveldb::DB::Open (options, "/ tmp/testdb", & db); assert (status.ok ());...
If you want to raise an error if the database already exists, add the following line before the leveldb::DB::Open call:
Options.error_if_exists = true; shuts down the database
After completing the database operation, you only need to delete the database object. Example:
... Open the db as described above...... Do something with db... Delete db; read and write
The database provides Put,Delete and Get methods to modify / query the database. As follows:
Std::string value; leveldb::Status s = db- > Get (leveldb::ReadOptions (), key1, & value); if (s.ok ()) s = db- > Put (leveldb::WriteOptions (), key2, value); if (s.ok ()) s = db- > Delete (leveldb::WriteOptions (), key1); concurrency
A database can only be opened by one process at a time. Leveldb acquires a lock from the operating system to prevent multiple processes from opening the same database at the same time. In a single process, the same leveldb::DB object can be safely used by multiple concurrent threads, that is, different threads can write, get an iterator, or call Get without requiring any external synchronization primitives (the leveldb implementation ensures the required synchronization). But other objects, such as Iterator or WriteBatch, need external synchronization guarantees, and if two threads share such objects, they need to use their own locks for mutually exclusive access. See the corresponding header file for details.
At present, leveldb has marked 24.2K on Github and 5.3K accumulatively (Github address: https://github.com/google/leveldb)).
What is leveldb above? have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, 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.