[infinispan-issues] [JBoss JIRA] (ISPN-2779) Lost data on remotecache get() after put()

ThienLong Hong (JIRA) jira-events at lists.jboss.org
Thu Jan 31 03:48:51 EST 2013


ThienLong Hong created ISPN-2779:
------------------------------------

             Summary: Lost data on remotecache get() after put()
                 Key: ISPN-2779
                 URL: https://issues.jboss.org/browse/ISPN-2779
             Project: Infinispan
          Issue Type: Bug
          Components: Distributed Cache, Eviction, Loaders and Stores, Server
    Affects Versions: 5.2.0.CR3, 5.1.6.FINAL
         Environment: Windows 7SP1 Pro
JDK 7 or JRE6
            Reporter: ThienLong Hong
            Assignee: Tristan Tarrant


I'm start server Infinispan follow comand:
./startServer.sh -r hotrod -c infinispan-distribution.xml -l 192.168.23.120 -Djgroups.bind_addr=192.168.23.120

Here is content of infinispan-distribution.xml:
<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="urn:infinispan:config:5.1 http://www.infinispan.org/schemas/infinispan-config-5.1.xsd"
   xmlns="urn:infinispan:config:5.1">

 <global>
  <transport>
   <properties>
    <property name="configurationFile" value="jgroups-tcp.xml">
   </property></properties>
  </transport>
 </global>
 <default>
  <clustering mode="distribution">
   <sync />
   <hash numOwners="2" />
  </clustering>
 </default>

 <namedCache name="myCache">
  <clustering mode="distribution">
   <sync />
   <hash numOwners="2" />
  </clustering>
 </namedCache>
 <namedCache name="evictionCache">
	<clustering mode="distribution">
	   <sync />
	   <hash numOwners="2" rehashEnabled="true" rehashRpcTimeout="600000" numVirtualNodes="50"/>
	</clustering>
	<eviction
	maxEntries="10000"
	strategy="LRU"
	/>

	<loaders passivation="true" preload="false">
		<loader class="org.infinispan.loaders.file.FileCacheStore" fetchPersistentState="true" purgeOnStartup="false">
		<properties>
			<property name="location" value="data"/>
		</properties>
		</loader>
	</loaders>
 </namedCache>
</infinispan>

I write a simple program to test benmark of infinispan but i got problem of lost data. I put many key-value but when i retrieve it return null.
Here is my program soucecode:
package vn.vccorp.benmark.infinispan;

import java.io.FileWriter;
import java.io.PrintWriter;
import java.net.URL;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager;

public class Benmark implements Callable<Void> {
	private static final int MAX_LENGHT = 20;
	private static final int MIN_LENGHT = 8;
	private Map<String, String> accs = new LinkedHashMap<String, String>();
	private final Random random = new Random(System.currentTimeMillis());
	private RemoteCache<String, String> rc;
	private boolean getOperator = false;

	public Benmark(RemoteCache<String, String> rc, int numAcc) {
		generateRandomAccs(numAcc);
		this.rc = rc;
	}

	/**
	 * @param args
	 * @throws InterruptedException
	 */
	public static void main(String[] args) throws InterruptedException {
		URL resource = Thread.currentThread().getContextClassLoader()
				.getResource("hotrod-client.properties");
		RemoteCacheManager rcm = new RemoteCacheManager(resource, true);
		RemoteCache<String, String> rc = rcm.getCache("evictionCache");
		List<Benmark> bens = new ArrayList<Benmark>();
		int numThreads = Runtime.getRuntime().availableProcessors() * 2;
		int numAccsPerThread = 5000;
		for (int i = 0; i < numThreads; ++i) {
			bens.add(new Benmark(rc, numAccsPerThread));
		}
		long time = testOperator(bens);
		System.out.println("finish test Put with "
				+ (numThreads * numAccsPerThread) + " records in "
				+ (time) + "ns");
		for (Benmark benmark : bens) {
			benmark.setGetOperator(true);
		}
		time = testOperator(bens);
		System.out.println("finish test Get with "
				+ (numThreads * numAccsPerThread) + " records in "
				+ (time) + "ns");
		rcm.stop();
		saveDataTest(bens);
	}

	private static void saveDataTest(List<Benmark> bens) {
		PrintWriter writer = null;
		try {
			writer = new PrintWriter(new FileWriter("data_test.txt"));
			for (Benmark ben : bens) {
				for (Entry<String, String> entry : ben.getAccs().entrySet()) {
					writer.println(entry.getKey());
					writer.println(entry.getValue());
				}
			}
		} catch (Exception e) {
			// TODO: handle exception
		} finally {
			if (writer != null) {
				writer.close();
			}
		}
	}

	private static long testOperator(List<Benmark> bens) throws InterruptedException {
		ExecutorService pool = Executors.newCachedThreadPool();
		long time = System.nanoTime();
		pool.invokeAll(bens);
		pool.shutdown();
		while (!pool.awaitTermination(1, TimeUnit.MINUTES)) {
		}
		long end = System.nanoTime();
		return end - time;
	}

	private void generateRandomAccs(int numberAcc) {
		String user = null;
		String pass = null;
		for (int i = 0; i < numberAcc;) {
			user = randomString();
			pass = randomString();
			if (getAccs().put(user, pass) == null) {
				++i;
			}
		}
	}

	private String randomString() {
//		int len = MIN_LENGHT + random.nextInt(MAX_LENGHT - MIN_LENGHT);
//		StringBuilder builder = new StringBuilder(len);
//		for (int i = 0; i < len; ++i) {
//			char c = (char) (32 + random.nextInt(126 - 32));
//			builder.append(c);
//		}
//		return builder.toString();
		return UUID.randomUUID().toString();
	}

	@Override
	public Void call() {
		if (!getOperator) {
			System.out.println("Start test PUT");
			long startPut = System.nanoTime();
			for (Entry<String, String> acc : getAccs().entrySet()) {
				rc.put(acc.getKey(), acc.getValue());
			}
			long endPut = System.nanoTime();
			System.out
					.println("Finish test PUT: " + (endPut - startPut) + "ns");
		} else {
			System.out.println("Start test GET");
			long startGet = System.nanoTime();
			for (Entry<String, String> acc : getAccs().entrySet()) {
				if (rc.get(acc.getKey()) == null) {
					System.err.println("Error get data");
					break;
				}
			}
			long endGet = System.nanoTime();
			System.out
					.println("Finish test GET: " + (endGet - startGet) + "ns");
		}
		return null;
	}

	public boolean isGetOperator() {
		return getOperator;
	}

	public void setGetOperator(boolean getOperator) {
		this.getOperator = getOperator;
	}

	public Map<String, String> getAccs() {
		return accs;
	}

	public void setAccs(Map<String, String> accs) {
		this.accs = accs;
	}

}



--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the infinispan-issues mailing list