自动调整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个回答

当数据库增长时,



LevelDB在后台线程中压缩SST文件。 由于这些文件是不可变的,因此可以通过创建新文件,然后删除旧文件来工作。 因此,此“压缩”步骤需要(临时)额外的磁盘空间。</ p>
</ div>

展开原文

原文

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.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐