Async client ArrayIndexOutOfBoundsException

My issue: “this.eventState = cluster.eventState[loop.index]” in NettyCommand.java is getting the exception. Could someone help me in this community? Thanks.

Update: I changed code from “new NioEventLoopGroup(4)” to “new NioEventLoopGroup(1)”, then the exception is gone, but the put is very slow, after insert a few records, then it just stuck at there, without any exception, do you guys know why?

My code:

    AsyncClient client = new AsyncClient(null, new Host("localhost", 3000));
    EventPolicy eventPolicy = new EventPolicy();
    EventLoopGroup group = new NioEventLoopGroup(4);
    EventLoops eventLoops = new NettyEventLoops(eventPolicy, group);
    EventLoop eventLoop = eventLoops.next();
    client.put(eventLoop, new WriteHandler(), writePolicy, key, bin);

Exception:

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at com.aerospike.client.async.NettyCommand.<init>(NettyCommand.java:77)
at com.aerospike.client.async.NettyEventLoop.execute(NettyEventLoop.java:60)
at com.aerospike.client.AerospikeClient.put(AerospikeClient.java:391)

version:

   <dependency>
        <groupId>com.aerospike</groupId>
        <artifactId>aerospike-client</artifactId>
        <version>4.0.7</version>
    </dependency>


    <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-all</artifactId>
        <version>4.1.14.Final</version>
    </dependency>

You are mixing the obsolete AsyncClient with the new AerospikeClient async functionality. Do not use AsyncClient. Instead, do the following.

EventPolicy eventPolicy = new EventPolicy();
EventLoopGroup group = new NioEventLoopGroup(4);
EventLoops eventLoops = new NettyEventLoops(eventPolicy, group);

ClientPolicy clientPolicy = new ClientPolicy();
clientPolicy.eventLoops = eventLoops;

AerospikeClient client = new AerospikeClient(clientPolicy, new Host("localhost", 3000));

EventLoop eventLoop = eventLoops.next();
client.put(eventLoop, new WriteHandler(), writePolicy, key, bin);

Hi, Brian, thanks for helping out, I appreciate it, it works!!!

I got a new issue. I am making aysnc put operation in a while loop, which is about 2000 loop. However, I could only put only a few hundred records, then started to get “accept: Too many open files” as following figure shows:

image

I used “ulimit -n” command to check the max open files limit on my machine, which is 20000. I then looked at the link below, which says aerospike default setting is 100000.

https://discuss.aerospike.com/t/increase-maximum-number-of-openfiles/1372

My question is how to change the default setting to the same as my machine?

Thanks, Yi

See example for writing records in async.