Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

please make all starter examples work without multicast #139

Open
shimondoodkin opened this issue Jul 15, 2019 · 3 comments
Open

please make all starter examples work without multicast #139

shimondoodkin opened this issue Jul 15, 2019 · 3 comments

Comments

@shimondoodkin
Copy link

shimondoodkin commented Jul 15, 2019

Please make all starter examples work without multicast and like on one self-contained machine. one machine that will be able to scale out later if required.

"Multicast is simple and efficient," but is not supported by most public clouds and VPNs and most important not supported by developer machines.

It makes a huge problem for anyone who is just starting (not scaling).
A high configuration barrier is bad for the product adaptation, and pain for new users.

The "quick start" example

https://griddb.net/en/docs/documents/2-3_run-your-first-griddb-node-cluster.php

does not explain the not-multicast way and newcomers stop with a not working software. Only those who insist need to invest many hours to learn how to do the not-multicast whatever or setup multicast are able to try GridDb. to just see if it is a good match for the software they develop.

@shimondoodkin
Copy link
Author

shimondoodkin commented Jul 15, 2019

parts of my solution

netstat -g # ran this and found out my system doesn't support multicast

#seems outdated article, configuration is a bit different, also there is now transactions in gs_cluster.json
# https://griddb.net/en/docs/documents/6-8_tuning.php
# https://griddb.net/en/blog/griddb-using-fixed-list-or-multicast-clustering/


su gsadm

cd ~

# changing to provider list
# install nodejs if you want to use nodejs
# https://github.com/nodesource/distributions/blob/master/README.md

nano provider.js

// this is nodejs file, requires nodejs 10+ with async support
var http = require('http');
var url = require('url');

var readFile=require('util').promisify(require('fs').readFile);

async function notification_provider(url,req,res){
 if(url==='/notification/provider')
 {
  res.writeHead(200, {'Content-type':'application/json'});
  res.end(await readFile('provider.json'))
  return true;
 }
}

http.createServer(async function(req, res){
   try{
   try{
    purl=url.parse(req.url,true);
    console.log(new Date().toISOString(),req.connection.remoteAddress,purl.pathname);

    if(await notification_provider(purl.pathname,req,res) ) return ;

   }
   catch(e)
   {
     console.log(e.stack);
     res.writeHead(500, {'Content-type':'text/plan'});
     res.end(e.stack);
     return;
   }
   res.writeHead(404, {'Content-type':'text/plan'});
   res.end('Not Found');
   } catch(e){ console.log(e.stack); }
}).listen(10080,function(){
   console.log('running at http://' + this.address().address + ':' + this.address().port);
});





 nano provider.json
[
  {
    "cluster": {"address":"127.0.0.1", "port":10010},
    "sync": {"address":"127.0.0.1", "port":10020},
    "system": {"address":"127.0.0.1", "port":10040},
    "transaction": {"address":"127.0.0.1", "port":10001}
  }
]

node provider.js
# test
curl http://127.0.0.1:10080/notification/provider


# conf/gs_cluster.json
# notificationAddress(IPV4 only)+notificationPort OR notificationMember OR notificationProvider, are mutualy exclusive.
# so remove enteries of notificationAddress and notificationPort.
# transaction section seems for multicast only so remove it too https://griddb.net/en/docs/manuals/v3.1/GridDB_TechnicalReference.html#sec-5.1  (i did not found there configuration of provider url).
# add notificationProvider in cluster:

                "notificationProvider": {
                 "url":"http://127.0.0.1/notification/provider",
                 "updateInterval":"30s"
                }
				

cat conf/gs_cluster.json
{
        "dataStore":{
                "partitionNum":128,
                "storeBlockSize":"64KB"
        },
        "cluster":{
                "clusterName":"defaultCluster",
                "replicationNum":1,
                "notificationInterval":"5s",
                "heartbeatInterval":"5s",
                "loadbalanceCheckInterval":"180s",
                "notificationProvider": {
                        "url":"http://127.0.0.1/notification/provider",
                        "updateInterval":"30s"
                }
        },
        "sync":{
                "timeoutInterval":"30s"
        }
}







# stat node
gs_startnode
gs_joincluster -c defaultCluster -u admin/admin


# stop node
# gs_leavecluster  -u admin/admin  -f
# gs_stopnode -u admin/admin




# build jar

cd ~
git clone https://github.com/griddb/griddb_nosql.git source

#to build jar need ant 
# apt install ant
# or 
# yum install ant

cd source/java_client/
ant

#it is easier to start with a java client.
#create java sample for testing

cd ~
mkdir gsSample
cp source/docs/sample/program/Sample1.java gsSample/
nano gsSample/Sample1.java


# change notificationAddress to notificationProvider
# remove notificationPort,
# update args number
# like:

       public static void main(String[] args) throws GSException {

                // Get a GridStore instance
                Properties props = new Properties();
                props.setProperty("notificationProvider", args[0]); // set this http://griddb.org/griddb_nosql/manual/GridDB_API_Reference.html#sec-5-1
                props.setProperty("clusterName", args[1]);
                props.setProperty("user", args[2]);
                props.setProperty("password", args[3]);
                GridStore store = GridStoreFactory.getInstance().getGridStore(props);


# build the sample
export CLASSPATH=/var/lib/gridstore/source/bin/gridstore.jar:.
javac gsSample/Sample1.java
java gsSample/Sample1 http://127.0.0.1:10080/notification/provider  defaultCluster admin admin


# I did not have a service, sure better to create systemd file, but the following also works.

if there is no service may be to use cron like 


there is "screen" - a program, window manager for console in linux

# apt install screen 
# or
# yum install screen

# screen command parts explanation:

# -dmS name     Start as daemon: Screen session in detached mode.
# trap 'echo sigint traped' INT;  - prevent exiting from screen when bash ends, prevent accidential Control+c
# ;  bash" at end - after program ends start bash
# the last argument of screen is the shell command

# the screen command structure is like:
# screen -dmS "SCREEN NAME"        bash -c "trap 'echo sigint traped' INT; COMMAND    ;  bash"
#


# in cron there is @reboot keyword instead of time of day to start once on reboot

# to edit cron run:

crontab -e 

add the folowing line to crontab:

@reboot screen -dmS "griddb provider.js" bash -c "trap 'echo sigint traped' INT; cd /var/lib/gridstore/ ;   node provider.js    ;  bash"


# maybe use this, not sure how griddb starts after restart
# @reboot screen -dmS "griddb" bash -c "trap 'echo sigint traped' INT;  cd /var/lib/gridstore/;  gs_startnode;  gs_joincluster -c defaultCluster -u admin/admin   ;  bash"





@knonomura
Copy link
Member

Thank you so much for your comment and solution.
I'd like to improve Quick Start Guide with reference to your comments.

@Leilaam40
Copy link

Thanks , I will try to use your knowledge.
I am studying a lot, because I want to be a developer and work in area.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants