doukui9491
2019-02-04 11:39
浏览 140
已采纳

自动调整levelDB磁盘空间?

I am using Go to store keys/values in the levelDB database. While i am inserting new key/values in the LevelDB, I checked the disk space used by leveldbfile Folder, it increases and then decreases in cycles.

  ➜  loomio git:(master) ✗ du -h leveldbfile
  7.4M  leveldbfile
  ➜  loomio git:(master) ✗ du -h leveldbfile
  1.2M  leveldbfile
  ➜  loomio git:(master) ✗ du -h leveldbfile
  8.3M  leveldbfile
  ➜  loomio git:(master) ✗ du -h leveldbfile
  8.4M  leveldbfile
  ➜  loomio git:(master) ✗ du -h leveldbfile
  6.0M  leveldbfile
  ➜  loomio git:(master) ✗ du -h leveldbfile
  3.6M  leveldbfile
  ➜  loomio git:(master) ✗ du -h leveldbfile
   11M  leveldbfile
  ➜  loomio git:(master) ✗ du -h leveldbfile
   10M  leveldbfile
  ➜  loomio git:(master) ✗ du -h leveldbfile
  3.7M  leveldbfile
  ➜  loomio git:(master) ✗ du -h leveldbfile
  1.2M  leveldbfile
  ➜  loomio git:(master) ✗ du -h leveldbfile
  8.3M  leveldbfile
  ➜  loomio git:(master) ✗ du -h leveldbfile
  6.0M  leveldbfile
  ➜  loomio git:(master) ✗ du -h leveldbfile
  3.7M  leveldbfile
  ➜  loomio git:(master) ✗ du -h leveldbfile
  1.4M  leveldbfile
  ➜  loomio git:(master) ✗ du -h leveldbfile
  8.5M  leveldbfile

The code for Storing email, password for users is

        func AddUser(dbSession config.Database, user *models.User) (string, error) {

            user_id := uuid.NewV4()
            user.UserID = user_id.String()
            ok := RetreiveSecondaryIndex(dbSession, user.Email)
            if ok {
                log.Println("This is the user id found in secondary index", ok)
                return "", errors.New("The email is already registered")

            }

            var network bytes.Buffer // Stand-in for a network connection
            enc := gob.NewEncoder(&network)

            err := enc.Encode(user)
            if err != nil {
                log.Println("Error in encoding gob")
                return "", err
            }


            err = dbSession.DBSession.Put([]byte(user.UserID), network.Bytes(), nil)
            //dberr := userCollection.Insert(user)
            fmt.Println(err)
            if err != nil {
                log.Println(err)
                return "", err
            }

            AddSecondaryIndex(dbSession, user.Username, user.Email)

            return user.UserID, nil
        }

Why is LevelDB readjusting its disk space and on what basis?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongyingming8970 2019-04-02 13:57
    已采纳

    LevelDB compacts SST files in a background thread while the database grows. Since these files are immutable, this works by creating new ones, and then removing the old ones. Hence, this ‘compaction’ step requires (temporarily) extra disk space.

    打赏 评论

相关推荐 更多相似问题