Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto Shrink dont get triggered #37

Open
h3ku opened this issue Jun 7, 2018 · 7 comments
Open

Auto Shrink dont get triggered #37

h3ku opened this issue Jun 7, 2018 · 7 comments

Comments

@h3ku
Copy link

h3ku commented Jun 7, 2018

Hi,

I have a program that performs some crawling, store and update data in buntdb and stops, after a few minutes a crontab launch de program again.

I don't know why but the database size grows and grows, containing some keys duplicated more than 50 times (Ending in multiple GB values completely full of duplicates).

There's any way I can force BuntDB to shrink the file at the end of every execution of the program or something like this?

@h3ku
Copy link
Author

h3ku commented Jun 7, 2018

I just make it work with a db.Shrink() at the end, it works fine but I don't have clues of why the AutoShrink don't work.

@tidwall
Copy link
Owner

tidwall commented Jun 7, 2018

Hi,

I'm sorry to hear that your running into issues. I would like to reproduce this issue on my side.

Do you update your config using the db.WriteConfig function? If so, could you provide your configuration code?

@tidwall
Copy link
Owner

tidwall commented Jul 10, 2018

Are you still running into this issue? I wasn't able to reproduce it.

@tidwall
Copy link
Owner

tidwall commented Jul 14, 2018

I’m closing this for now but feel free to reopen if you are still running into problems. Thanks!

@tidwall tidwall closed this as completed Jul 14, 2018
@cute-angelia
Copy link


func TestAutoShrink2(t *testing.T) {
	dbpath := "/tmp/test_2.db"
	if db, err := buntdb.Open(dbpath); err == nil {
		db.SetConfig(buntdb.Config{
			AutoShrinkDisabled:   true, // not work
			AutoShrinkMinSize:    1,    // not work
			AutoShrinkPercentage: 30,
		})
		for i := 0; i < 20; i++ {
			writeCache2(db)
			time.Sleep(time.Second * 5)
		}
	}
}

func writeCache2(db *buntdb.DB) {
	for i := 0; i < 10000; i++ {
		log.Println("--> ", i)
		val := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
		db.Update(func(tx *buntdb.Tx) error {
			tx.Set(fmt.Sprintf("%s%d", "test", i), val, &buntdb.SetOptions{Expires: true, TTL: time.Hour})
			return nil
		})
	}
}


the db file size is sustained growth ... without Shrink

I would it like file-rotatelogs

@cute-angelia
Copy link

@tidwall

@tidwall
Copy link
Owner

tidwall commented Jul 23, 2021

@cute-angelia

Are you wanting to disable AutoShrink?

Your code is disabling the AutoShrink. This will make the database continue grow until db.Shrink() is called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants