DistributedSqlEngine:open( parameter list )

Open the connections with servers.

Prototype

 
    bool open(char const* const* nodes, int nNodes, 
            int nReplicas = 1, 
            ReplicationType replType = SQL_REPLICATION,
            int maxConnectAttempts = 10, 
            int* badNode = NULL, 
            bool localDomain = false, 
            void* sslParameters = NULL,
            timer_unit connectTimeout = 2*1000, 
            timer_unit readTimeout = 1200*1000,
            int compressionLevel = 0);
 

Arguments

nodes An array with the node names and ports ("NAME:PORT")
nNodes The number of nodes
nReplicas The number of replicas; this number should be a divider of nNodes meaning that the remainder of nNodes / nReplicas is 0. For example, the values of nNodes and nReplicas could be (4 and 2) or (12 and 3) but not (6 and 4) because 6 % 4 = 2
replType The replication method
maxConnectAttempts The maximum number of attempts to connect to the server
badNode If this parameter is not null and the open fails, then the index of the not unavailable node is stored in badNode
localDomain Indicates that Unix Domain Socket instead of networked TCP socket is used for RSQL communication which is possible only when server and client are on the same host
sslParameters A pointer to a mco_ssl_params_t structure containing SSL connection settings
connectTimeout The timeout for each connect attempt in milliseconds; so the total connection time can be up to connectTimeout * maxConnectionAttempts milliseconds
readTimeout The timeout for read operations in milliseconds
compression_level The level of compression: 0 = no compression; 1 = best speed, 9 - best compression. Default value is 0

Description

This method opens an eXtremeDB database, an eXtremeDB SQL mapper and the McoSqlEngine instance with the list of parameters specified.

Returns

This method returns true if the connection to the server was successfully established, false otherwise.

Example

     
    const size_t MAX_CONNECT_ATTEMPTS = 10;
    const size_t MAX_NODES = 1024;
     
    int main(int argc, char* argv[])
    {
        MCO_RET rc;
        char* nodes[MAX_NODES];
        bool localDomain = false;
        int redundancy = 1;
        ...
        while (i < argc && (*argv[i] == '-' || *argv[i] == '@')) 
        {
            nodes[nNodes++] = &argv[i][1];
        }
        ...
        DistributedSqlEngine* client = new DistributedSqlEngine();
        int badNode = -1;
        if (!client->open(nodes, nNodes, redundancy,  
            DistributedSqlEngine::SQL_REPLICATION,  
            MAX_CONNECT_ATTEMPTS, &badNode, localDomain))  
        {
            fprintf(stderr, "Failed to connect to node %d\n", badNode);
            return 1;
        }
        ...
    }