2016-12-16 47 views
1

我已經在Ubuntu上設置了一個riak服務器。Riak java客戶端,execute()永遠不會返回

http://192.168.0.102:8098/ping回報 「OK」

我試圖遠程連接它使用了Riak Java客戶端(2.1.1)使用下面的代碼。 client.execute()永遠不會返回。我也附上日誌。在控制檯上

public class Testing { 

    public static void main(String[] args) throws ExecutionException, 
      InterruptedException, UnknownHostException { 

     RiakClient client = RiakClient.newClient(8098, "192.168.0.102"); 

     // put some stuff 

     Namespace ns = new Namespace("TestBucket"); 
     Location location = new Location(ns, "TestKey"); 

     String myData = "TestValue"; 

     StoreValue store = new StoreValue.Builder(myData) 
     .withLocation(location).build(); 
     Response rv = client.execute(store);   // << NEVER GETS PAST THIS 

     System.out.println("write done"); 

     // get some stuff 
     FetchValue fv = new FetchValue.Builder(location).build(); 
     FetchValue.Response response = client.execute(fv); 
     String obj = response.getValue(String.class); 

     System.out.println(obj); 
     System.out.println("fetch done"); 

    } 

} 

日誌是...掛起的線程的

17:19:40.841 [main] DEBUG i.n.u.i.l.InternalLoggerFactory - Using SLF4J as the default logging framework 
17:19:40.865 [main] DEBUG i.n.c.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 16 
17:19:40.891 [main] DEBUG i.n.util.internal.PlatformDependent0 - java.nio.Buffer.address: available 
17:19:40.892 [main] DEBUG i.n.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available 
17:19:40.893 [main] DEBUG i.n.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available 
17:19:40.894 [main] DEBUG i.n.util.internal.PlatformDependent0 - direct buffer constructor: available 
17:19:40.894 [main] DEBUG i.n.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true 
17:19:40.894 [main] DEBUG i.n.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.<init>(long, int): available 
17:19:40.896 [main] DEBUG io.netty.util.internal.Cleaner0 - java.nio.ByteBuffer.cleaner(): available 
17:19:40.896 [main] DEBUG i.n.util.internal.PlatformDependent - Platform: Windows 
17:19:40.897 [main] DEBUG i.n.util.internal.PlatformDependent - Java version: 8 
17:19:40.897 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.noUnsafe: false 
17:19:40.897 [main] DEBUG i.n.util.internal.PlatformDependent - sun.misc.Unsafe: available 
17:19:40.898 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.noJavassist: false 
17:19:40.899 [main] DEBUG i.n.util.internal.PlatformDependent - Javassist: unavailable 
17:19:40.899 [main] DEBUG i.n.util.internal.PlatformDependent - You don't have Javassist in your class path or you don't have enough permission to load dynamically generated classes. Please check the configuration for better performance. 
17:19:40.899 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\Rakesh\AppData\Local\Temp (java.io.tmpdir) 
17:19:40.900 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.bitMode: 32 (sun.arch.data.model) 
17:19:40.900 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false 
17:19:40.900 [main] DEBUG i.n.util.internal.PlatformDependent - io.netty.maxDirectMemory: 259522560 bytes 
17:19:40.921 [main] DEBUG io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false 
17:19:40.921 [main] DEBUG io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 
17:19:40.922 [main] DEBUG i.n.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available 
17:19:41.039 [main] DEBUG io.netty.channel.DefaultChannelId - -Dio.netty.processId: 2924 (auto-detected) 
17:19:41.041 [main] DEBUG io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false 
17:19:41.041 [main] DEBUG io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false 
17:19:41.162 [main] DEBUG io.netty.util.NetUtil - Loopback interface: lo (Software Loopback Interface 1, 127.0.0.1) 
17:19:41.163 [main] DEBUG io.netty.util.NetUtil - \proc\sys\net\core\somaxconn: 200 (non-existent) 
17:19:41.321 [main] DEBUG io.netty.channel.DefaultChannelId - -Dio.netty.machineId: e4:b3:18:ff:fe:6c:52:eb (auto-detected) 
17:19:41.321 [main] DEBUG i.n.util.internal.ThreadLocalRandom - -Dio.netty.initialSeedUniquifier: 0xb620b93d4006e503 
17:19:41.333 [main] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple 
17:19:41.333 [main] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.maxRecords: 4 
17:19:41.355 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 2 
17:19:41.355 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 2 
17:19:41.355 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 
17:19:41.355 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 
17:19:41.355 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 
17:19:41.355 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 
17:19:41.355 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 
17:19:41.355 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 
17:19:41.355 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 
17:19:41.355 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 
17:19:41.364 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled 
17:19:41.365 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 65536 
17:19:41.365 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 
17:19:41.406 [main] INFO com.basho.riak.client.core.RiakNode - RiakNode started; 192.168.0.102:8098 
17:19:41.407 [main] INFO c.basho.riak.client.core.RiakCluster - RiakCluster is starting. 
17:19:41.408 [main] INFO c.b.r.c.core.util.DefaultCharset - No desired charset found in system properties, the default charset 'windows-1252' will be used 
17:19:41.408 [main] INFO c.b.r.c.core.util.DefaultCharset - Initializing client charset to: windows-1252 
17:19:41.443 [main] DEBUG com.basho.riak.client.core.RiakNode - Attempting to acquire channel permit 
17:19:41.445 [main] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 32768 
17:19:41.445 [main] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 
17:19:41.445 [main] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 
17:19:41.445 [main] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 
17:19:41.447 [main] DEBUG com.basho.riak.client.core.RiakNode - Operation 28144878 being executed on RiakNode 192.168.0.102:8098 
17:19:41.461 [nioEventLoopGroup-2-10] DEBUG io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.bytebuf.checkAccessible: true 
17:19:41.463 [nioEventLoopGroup-2-10] DEBUG i.n.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: [email protected] 

調用堆棧

Thread [main] (Suspended) 
    Unsafe.park(boolean, long) line: not available [native method] 
    LockSupport.park(Object) line: not available  
    CountDownLatch$Sync(AbstractQueuedSynchronizer).parkAndCheckInterrupt() line: not available 
    CountDownLatch$Sync(AbstractQueuedSynchronizer).doAcquireSharedInterruptibly(int) line: not available 
    CountDownLatch$Sync(AbstractQueuedSynchronizer).acquireSharedInterruptibly(int) line: not available 
    CountDownLatch.await() line: not available 
    StoreOperation(FutureOperation<T,U,S>).await() line: 387  
    GenericRiakCommand$1(CoreFutureAdapter<T2,S2,T,S>).await() line: 90 
    StoreValue(RiakCommand<T,S>).execute(RiakCluster) line: 92 
    RiakClient.execute(RiakCommand<T,S>) line: 355 
    Testing.main(String[]) line: 29 

回答

0

一個簡單的代碼添加下面一行代碼的應該解決的事情,對你以後:

response rv = client.execute(store); 

add:

client.shutdown(); 

釋放該連接並繼續執行。

注意,你將需要因爲你關閉client創建對數據庫中的下一個請求一個新的連接或代替.execute()使用.executeAsync()

+0

但它不會通過該代碼行。我還在問題中添加了暫停線程的調用堆棧。 – RakeshPrasad

+0

如果您的代碼現在讀爲: 響應rv = client.execute(store); client.shutdown(); System.out.println(「write done」); 應執行打印語句。我已經在本地運行您的代碼,併成功地針對單個節點描述了上述更改。 – Craig

+0

當然,理想情況下它應該成功運行,因爲它在文檔中的參考代碼。但由於某種原因,它不適合我。我希望有人能夠幫助我找到日誌和暫停線程的調用堆棧的原因。 – RakeshPrasad

0

看起來您期待Riak java客戶端使用HTTP API進行連接。 Riak java客戶端只使用協議緩衝區進行連接;使用HTTP地址和端口將凍結。

0

同比不得不使用它,它的作品很好...

public static void main(String[] args) throws ExecutionException, 
     InterruptedException, UnknownHostException { 

    RiakClient client = RiakClient.newClient(8087,"192.168.0.65"); 

    // put some stuff 

    Namespace ns = new Namespace("TestBucket"); 
    Location location = new Location(ns, "TestKey"); 

    String myData = "TestValue"; 

    StoreValue store = new StoreValue.Builder(myData) 
    .withLocation(location).build(); 
    client.execute(store);   // << NEVER GETS PAST THIS 

    System.out.println("write done"); 

// get some stuff 
    FetchValue fv = new FetchValue.Builder(location).build(); 
    FetchValue.Response response = client.execute(fv); 
    String obj = response.getValue(String.class); 

    System.out.println(obj); 
    System.out.println("fetch done"); 

} 

希望你也將獲得...!

相關問題