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

MapDB is not reducing its size when all messages get deleted #1033

Open
prasaddige opened this issue Nov 20, 2023 · 2 comments
Open

MapDB is not reducing its size when all messages get deleted #1033

prasaddige opened this issue Nov 20, 2023 · 2 comments

Comments

@prasaddige
Copy link

  1. Created MapdB, physical size of file db is 2.00 MB (2,097,152 bytes)
  2. Insert 1000 messages into mapdb. Physical size of mapdb increased to 10.0 MB (10,485,760 bytes)
  3. Deleted all entries from mapDB

Expected: size of DB file should go back to 2 MB
Expected: Size of DB file stays at 10.0 MB

=========================================================================
Sample code to reproduce:
public static void main(String[] args) {
File file = new File("myMapDB.db");

	DB fileDB = DBMaker.fileDB(file).closeOnJvmShutdown().make();

	HTreeMap<String, String> hTreeMap = fileDB
			.hashMap(MAP_NAME, Serializer.STRING, Serializer.STRING)
			.expireMaxSize(20000)
			.expireAfterCreate(1, TimeUnit.DAYS)
			.modificationListener(new StringRetryFileListener())
			.createOrOpen();


	System.out.println("File Size Before Insert=" + FileUtils.sizeOf(file) + ", No of Entries=" + hTreeMap.size());

	for(int i = 0; i < 1000; i++) {
		hTreeMap.put(""+i, str);
	}

	System.out.println("File Size After Insert=" + FileUtils.sizeOf(file) + ", No of Entries=" + hTreeMap.size());

	for (Entry<String, String> entry : hTreeMap.getEntries()) {
		hTreeMap.remove(entry.getKey());
	}

	System.out.println("File Size After Delete=" + FileUtils.sizeOf(file) + ", No of Entries=" + hTreeMap.size());

	System.out.println("SIZE=" + hTreeMap.size());
}

=========================================================================

Output

File Size Before Insert=2097152, No of Entries=0
File Size After Insert=10485760, No of Entries=1000
File Size After Delete=10485760, No of Entries=0

@andrm
Copy link
Sponsor

andrm commented Nov 22, 2023

Try calling DB.getStore().compact()

@igalkin
Copy link

igalkin commented Mar 27, 2024

Set compaction threshold on the map creator to trigger automatic compaction when cleared space reaches certain level of the allocated space (20% in the below example):
.expireCompactThreshold(0.2)

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