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

ChronicleMap - Max Entry Limit reduces after removing few entries #400

Open
Aravind-Babu-18 opened this issue Feb 24, 2022 · 0 comments
Open

Comments

@Aravind-Babu-18
Copy link

Chronicle Map Versions I used - 3.22ea6 / 3.22ea5 / 3.21.86

I am trying to delete few unnecessary entries and add new entries. But the Chronicle Map throws Exception even before the configured Max Entries limit reaches.

Shown below a sample code.

ChronicleMap<ByteBuffer, ByteBuffer> main = ChronicleMapBuilder.of(ByteBuffer.class, ByteBuffer.class)
                                                                .name("main")
                                                                .entries(61500)
                                                                .averageKey(ByteBuffer.wrap(new byte[500]))
                                                                .averageValue(ByteBuffer.wrap(new byte[5120]))
                                                                .create();

SecureRandom random = new SecureRandom();
int failureCount = 0;
while (true)
{
	System.out.println();
	System.out.println("--------------------------\nMain Heap Size -> " + main.offHeapMemoryUsed());
	System.out.println();
	try
	{
		int mainEntries = main.size();
		while /* (true) Loop until error is thrown */ (mainEntries < 61500)
		{
			try
			{
				byte[] keyN = new byte[500];
				byte[] valueN = new byte[5120];
				random.nextBytes(keyN);
				random.nextBytes(valueN);

				main.put(ByteBuffer.wrap(keyN), ByteBuffer.wrap(valueN));
				mainEntries++;
			}
			catch (Throwable t)
			{
				System.out.println(">>>>>>>>>> !!! Max Entries is not yet reached !!! <<<<<<<<<<");
				failureCount++;
				break;
			}
		}
		System.out.println("Main Entries -> " + main.size());

		if(failureCount >= 10)
		{
			System.out.println();
			System.out.println("--------------------------\nTerminating the Program");
			break;
		}

		AtomicInteger entriesRemoved = new AtomicInteger(0);
		main.forEachEntry(c -> {
			if (entriesRemoved.get() < 7000)
			{
				c.context().remove(c);
				entriesRemoved.incrementAndGet();
			}
		});
		System.out.println("Removed " + entriesRemoved.get() + " Entries from Main");
	}
	catch (Throwable t)
	{
		break;
	}
}
main.close();

The above code yields the following result.

Added a Summary of the Result. Please see the drop-down for the full Result If needed
Main Heap Size -> 398061568

Main Entries -> 61500
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 796112896

>>>>>>>>>> !!! Max Entries is not yet reached !!! <<<<<<<<<<
Main Entries -> 43858
Removed 7000 Entries from Main
Main Heap Size -> 398061568

Main Entries -> 61500
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 398061568

Main Entries -> 61500
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 447817984

Main Entries -> 61500
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 746356480

Main Entries -> 61500
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 746356480

Main Entries -> 61500
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 746356480

Main Entries -> 61500
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 746356480

Main Entries -> 61500
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 746356480

Main Entries -> 61500
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 746356480

Main Entries -> 61500
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 746356480

Main Entries -> 61500
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 746356480

Main Entries -> 61500
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 746356480

Main Entries -> 61500
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 746356480

>>>>>>>>>> !!! Max Entries is not yet reached !!! <<<<<<<<<<
Main Entries -> 58362
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 796112896

>>>>>>>>>> !!! Max Entries is not yet reached !!! <<<<<<<<<<
Main Entries -> 51578
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 796112896

>>>>>>>>>> !!! Max Entries is not yet reached !!! <<<<<<<<<<
Main Entries -> 44611
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 796112896

>>>>>>>>>> !!! Max Entries is not yet reached !!! <<<<<<<<<<
Main Entries -> 38000
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 796112896

>>>>>>>>>> !!! Max Entries is not yet reached !!! <<<<<<<<<<
Main Entries -> 31039
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 796112896

>>>>>>>>>> !!! Max Entries is not yet reached !!! <<<<<<<<<<
Main Entries -> 24040
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 796112896

>>>>>>>>>> !!! Max Entries is not yet reached !!! <<<<<<<<<<
Main Entries -> 17071
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 796112896

>>>>>>>>>> !!! Max Entries is not yet reached !!! <<<<<<<<<<
Main Entries -> 10092
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 796112896

>>>>>>>>>> !!! Max Entries is not yet reached !!! <<<<<<<<<<
Main Entries -> 43858
Removed 7000 Entries from Main

--------------------------
Main Heap Size -> 796112896

>>>>>>>>>> !!! Max Entries is not yet reached !!! <<<<<<<<<<
Main Entries -> 36874

--------------------------
Terminating the Program

In the above result in the drop-down, We can see that the Max Entries of the Map got decreased in the subsequent iterations

In the Issue 128, it was said the entries are deleted properly. Then why the above behavior happens?

Is it an issue? or Is the Chronicle Map not designed for such usage pattern?

Please Refer my question in Stackoverflow also.

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

1 participant