• <fieldset id="8imwq"><menu id="8imwq"></menu></fieldset>
  • <bdo id="8imwq"><input id="8imwq"></input></bdo>
    最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
    問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
    當(dāng)前位置: 首頁 - 科技 - 知識百科 - 正文

    LevelDB:一個快速輕量級的key-value存儲庫(譯)

    來源:懂視網(wǎng) 責(zé)編:小采 時間:2020-11-09 10:23:38
    文檔

    LevelDB:一個快速輕量級的key-value存儲庫(譯)

    LevelDB:一個快速輕量級的key-value存儲庫(譯):作者: JeffDean,SanjayGhemawat 原文: 譯者: phylips@bmy2011-8-16 譯文: 打開一個數(shù)據(jù)庫 一個 LevelDB 數(shù)據(jù)庫有一個文件系統(tǒng)目錄名稱與之關(guān)聯(lián)。該數(shù)據(jù)庫的所有內(nèi)容都存儲在該目錄下。下面的例子展示了如何打開一個數(shù)據(jù)庫,或者如何在必要的時候創(chuàng)建一個
    推薦度:
    導(dǎo)讀LevelDB:一個快速輕量級的key-value存儲庫(譯):作者: JeffDean,SanjayGhemawat 原文: 譯者: phylips@bmy2011-8-16 譯文: 打開一個數(shù)據(jù)庫 一個 LevelDB 數(shù)據(jù)庫有一個文件系統(tǒng)目錄名稱與之關(guān)聯(lián)。該數(shù)據(jù)庫的所有內(nèi)容都存儲在該目錄下。下面的例子展示了如何打開一個數(shù)據(jù)庫,或者如何在必要的時候創(chuàng)建一個

    作者: JeffDean,SanjayGhemawat 原文: 譯者: phylips@bmy2011-8-16 譯文: 打開一個數(shù)據(jù)庫 一個 LevelDB 數(shù)據(jù)庫有一個文件系統(tǒng)目錄名稱與之關(guān)聯(lián)。該數(shù)據(jù)庫的所有內(nèi)容都存儲在該目錄下。下面的例子展示了如何打開一個數(shù)據(jù)庫,或者如何在必要的時候創(chuàng)建一個

    作者:Jeff Dean, Sanjay Ghemawat

    原文:

    譯者:phylips@bmy 2011-8-16

    譯文:

    打開一個數(shù)據(jù)庫

    一個LevelDB數(shù)據(jù)庫有一個文件系統(tǒng)目錄名稱與之關(guān)聯(lián)。該數(shù)據(jù)庫的所有內(nèi)容都存儲在該目錄下。下面的例子展示了如何打開一個數(shù)據(jù)庫,或者如何在必要的時候創(chuàng)建一個:

    #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());

    ...

    如果你想在數(shù)據(jù)庫已經(jīng)存在的情況下,讓上面的代碼產(chǎn)生一個錯誤,需要再Open調(diào)用之前加入如下一行:

    options.error_if_exists = true;

    狀態(tài)(status)

    leveldb::Status s = ...;

    if (!s.ok()) cerr << s.ToString() << endl;

    關(guān)閉數(shù)據(jù)庫

    在完成一個數(shù)據(jù)庫的處理之后,直接刪除該數(shù)據(jù)庫對象即可。

    ... open the db as described above ...

    ... do something with db ...

    delete db;

    讀操作與寫操作

    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);

    原子性更新

    #include "leveldb/write_batch.h"

    ...

    std::string value;

    leveldb::Status s = db->Get(leveldb::ReadOptions(), key1, &value);

    if (s.ok()) {

    leveldb::WriteBatch batch;

    batch.Delete(key1);

    batch.Put(key2, value);

    s = db->Write(leveldb::WriteOptions(), &batch);

    }

    WriteBatch 同步性的寫操作

    leveldb::WriteOptions write_options;

    write_options.sync = true;

    db->Put(write_options, ...);

    并發(fā) 迭代

    下面的例子用來說明如何打印出數(shù)據(jù)庫中的所有key value對。

    leveldb::Iterator* it = db->NewIterator(leveldb::ReadOptions());

    for (it->SeekToFirst(); it->Valid(); it->Next()) {

    cout << it->key().ToString() << ": " << it->value().ToString() << endl;

    }

    assert(it->status().ok());

    // Check for any errors found during the scan

    delete it;

    for (it->Seek(start);

    it->Valid() && it->key().ToString() < limit;

    it->Next()) {

    ...

    }

    for (it->SeekToLast(); it->Valid(); it->Prev()) {

    ...

    }

    Snapshots

    leveldb::ReadOptions options;

    options.snapshot = db->GetSnapshot();

    ... apply some updates to db ...

    leveldb::Iterator* iter = db->NewIterator(options);

    ... read using iter to view the state when the snapshot was created ...

    delete iter;

    db->ReleaseSnapshot(options.snapshot);

    leveldb::Snapshot* snapshot;

    leveldb::WriteOptions write_options;

    write_options.post_write_snapshot = &snapshot;

    leveldb::Status status = db->Write(write_options, ...);

    ... perform other mutations to db ...

    leveldb::ReadOptions read_options;

    read_options.snapshot = snapshot;

    leveldb::Iterator* iter = db->NewIterator(read_options);

    ... read as of the state just after the Write call returned ...

    delete iter;

    db->ReleaseSnapshot(snapshot);

    Slice

    leveldb::Slice s1 = "hello";

    std::string str("world");

    leveldb::Slice s2 = str;

    std::string str = s1.ToString();

    assert(str == std::string("hello"));

    。比如下面代碼的就是有問題的:

    leveldb::Slice slice;

    if (...) {

    std::string str = ...;

    slice = str;

    }

    Use(slice);

    比較器

    class TwoPartComparator : public leveldb::Comparator {

    public:

    // Three-way comparison function:

    // if a < b: negative result

    // if a > b: positive result

    // else: zero result

    int Compare(const leveldb::Slice& a, const leveldb::Slice& b) const {

    int a1, a2, b1, b2;

    ParseKey(a, &a1, &a2);

    ParseKey(b, &b1, &b2);

    if (a1 < b1) return -1;

    if (a1 > b1) return +1;

    if (a2 < b2) return -1;

    if (a2 > b2) return +1;

    return 0;

    }

    // Ignore the following methods for now:

    const char* Name() const { return "TwoPartComparator"; }

    void FindShortestSeparator(std::string*, const leveldb::Slice&) const { }

    void FindShortSuccessor(std::string*) const { }

    };

    現(xiàn)在使用定制的比較器,創(chuàng)建一個數(shù)據(jù)庫:

    TwoPartComparator cmp;

    leveldb::DB* db;

    leveldb::Options options;

    options.create_if_missing = true;

    options.comparator = &cmp;

    leveldb::Status status = leveldb::DB::Open(options, "/tmp/testdb", &db);

    向后兼容(Backwards compatibility)

    性能

    可以通過改變include/leveldb/options.h里的默認(rèn)值來對性能進(jìn)行調(diào)整優(yōu)化。

    塊大小 壓縮

    聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文檔

    LevelDB:一個快速輕量級的key-value存儲庫(譯)

    LevelDB:一個快速輕量級的key-value存儲庫(譯):作者: JeffDean,SanjayGhemawat 原文: 譯者: phylips@bmy2011-8-16 譯文: 打開一個數(shù)據(jù)庫 一個 LevelDB 數(shù)據(jù)庫有一個文件系統(tǒng)目錄名稱與之關(guān)聯(lián)。該數(shù)據(jù)庫的所有內(nèi)容都存儲在該目錄下。下面的例子展示了如何打開一個數(shù)據(jù)庫,或者如何在必要的時候創(chuàng)建一個
    推薦度:
    標(biāo)簽: 一個 快速 存儲
    • 熱門焦點(diǎn)

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 精品亚洲一区二区三区在线播放| 久久99精品久久久久久齐齐| 亚洲一二成人精品区| 下载天堂国产AV成人无码精品网站| 精品成人免费自拍视频| 无码精品人妻一区二区三区免费看 | 久久精品蜜芽亚洲国产AV| 99久久精品国产一区二区蜜芽| 久久精品国产亚洲AV无码麻豆| 精品国产福利尤物免费| 久久久精品免费国产四虎| 国产午夜精品一区二区三区| 亚洲欧美激情精品一区二区| 精品久久久久久无码国产| 永久免费精品视频| 国产精品久久久久影院色| 久久香蕉超碰97国产精品| 亚洲精品乱码久久久久久不卡 | 亚洲成人精品久久| 国产福利91精品一区二区三区| 久久精品国产亚洲av麻豆小说 | 精品无码综合一区| 国产一区二区三区在线观看精品| 在线精品国产一区二区| 久久精品www| 欧美日韩精品在线| 欧美精品在线一区| 91久久精品视频| 99精品国产福利在线观看| 九九精品免视看国产成人| 精品福利资源在线| 99久久精品国产高清一区二区 | 亚洲国产综合精品中文字幕| 久久久99精品成人片中文字幕| 国产精品哟女在线观看| 99精品福利国产在线| 99久re热视频这里只有精品6| 国产精品 羞羞答答在线| 国产精品偷伦视频免费观看了| 国产精品无码久久久久| 国产午夜精品一区二区三区小说|