Aerospike.Client.AerospikeException: Invalid namespace


#1

Hello. A few days ago after update C# Aerospike Client to version 3.5.0 there were errors from the client:

Aerospike.Client.AerospikeException: Invalid namespace: XXXXXXX

Of course such namespace is created, but such error nevertheless periodically appears (not all the time, several times per hour). This error occurs when we use the lua script.

What could be the problem ?

PS. We use Aerospike cluster of two servers.


#2

What does the namespace name look like? Is it looking like some random string or something that may have been used in other clusters maybe?


#3

Maybe a code snippet would help here? Are there any logs on the server side (instability, exceptions, warnings,etc)?


#4

Unfortunately on server side there are no any unusual logs, or some logs that indicate a problem.

We use such simple lua script:

function Test (rec, bin, value) 
  if (EXISTS(rec, bin)) then
    m = rec[bin] + value
    rec[bin] = m
    UPDATE(rec)
    return m
  else
    rec[bin] = value
    UPDATE(rec)
    return value
  end
end

local function UPDATE(rec)
	if aerospike:exists(rec) then
		aerospike:update(rec)
	else
		aerospike:create(rec)
	end
end

#5

I doubt the lua script is related to the error. That error message is generated by the client before the lua command is even sent to the server.

The error means the namespace is not found in data partition map (keyed by namespace). This is odd because namespaces are statically configured on the server-side and never change while the server is running. When the AerospikeClient instance is constructed, the namespaces are retrieved from the servers. Namespaces are not deleted on the client after that initialization.

A snippet of the client code that calls the lua commands would be helpful.


#6

Thanks for the response. So that is our client code where we call the lua function:

public void func1 (int Id, int val)
        {
            try
            {
                var key = "P-" + Id;
                Key asKey = new Key(ns, set, key);
                client.Execute(null, asKey,"fix", "Test", Value.Get(binName), Value.Get(-val)); //fix - lua module name, Test - lua function name.
            }
            catch (Exception ex)
            {
                Logger.Current.LogError(GetType().Name, ex);
            }
        }

 public void func1 (int Id, int val)
        {
            List<Task> tasks = new List<Task>();
            foreach (var c in clients.Where(x => x.Value.Write))
            {
                if (c.Value.Client != null)
                {
                    tasks.Add(Task.Run(() => c.Value.Client.func1(Id, val)));
                }
            }
            Task.WaitAll(tasks.ToArray());
        }

Aerospike client parameters:

 public Cache (string host)
        {
            client = new AsyncClient(acp, host.Split(';').Select(x => new Host(x, 3000)).ToArray());
        }

        AsyncClient client;

        string ns = "xxxxx";
        string set = "yyyyy";
        string binName = "y";

        static Policy rp = new Policy
        {
            maxRetries = 3
        };

        static WritePolicy wp = new WritePolicy
        {
            recordExistsAction = RecordExistsAction.UPDATE,
            maxRetries = 3,
        };

        static AsyncClientPolicy acp = new AsyncClientPolicy
        {
            readPolicyDefault = rp,
            writePolicyDefault = wp,
            timeout = 2000, 
            failIfNotConnected = false
        };

And we call our previous functions in such way:

 Parallel.ForEach( JJJJJ, new ParallelOptions { MaxDegreeOfParallelism = maxT }, (fv) =>
                         {
                             try
                             {
                                 cCache.func1(fv.Key, fv.Value);
                             }
                             catch (Exception ex)
                             {
                                 Logger.Current.LogError(GetType().Name, ex);
                             }
                         });

And on the last catch ( catch (Exception ex) { Logger.Current.LogError(GetType().Name, ex); }) we get an error.


#7

It appears that you have multiple client instances. Is it possible that one of the client instances is not fully initialized or points to a different cluster with different namespaces?

Try printing out the namespaces when you get the error in Command.cs, GetSequenceNode().

if (!map.TryGetValue(partition.ns, out partitions))
{
	// Add these lines
	StringBuilder sb = new StringBuilder(1000);
	sb.Append("Invalid namespace: ");
	sb.Append(partition.ns);
	sb.Append(" current namespaces: ");

	foreach (string key in map.Keys)
	{
		sb.Append(key);
		sb.Append(' ');
	}				
	throw new AerospikeException(sb.ToString());
}

#8

Hi, Brian.

Is it possible that one of the client instances is not fully initialized or points to a different cluster with different namespaces?

Unfortunately no, it is not possible.

As for code that you sent us - we will try it. Thanks. I will write about the results.