Hi All, 

Ok, since i could not find much help anywhere. So, i went through the 
source code and found quite an interesting observation. 
Please, correct me if i am wrong. 

So, lets say you created a Server.createTcpServer("{-tcpAllowOthers}");. 
Well, this creates a h2 tcp server run on a localhost ip and port number 
9092,by default. However, if someone re-runs a Server on the same machine 
without specifying a port, the Server starts again. 
Now, you would be curious, same as i am, how can this be possible?

So what internally happens, actually is, that the Server again tries to 
create a tcp socket running on the same, default, port 9092, which 
obviously, will fail to start, due to port conflict. Hence, it will come 
back and catch that exception and then try to run on any random port, by 
instantiating a java.net.ServerSocket on port number 0. which actually 
means that java automatically selects a port for the socket to open, out of 
all the valid list of port numbers that it maintains with itself to use. 
So, now most probably, since you would not be using most of the ports in 
your local, hence there is near to 1 probability that you may end up 
starting the H2 Server on some random port. However, you might not be 
knowing on which port its running. 

More interestingly, If you are trying to run more than one server instance 
in the same JVM instance, then the TCPServer class which implements the 
Service interface, has a static MAP of port numbers to the TCPSERVER 
instances, which maintains this port number to server instance running map 
with itself. Every time you stop one server, the entry is removed from this 
map. 

But, if all Servers are running in separate JVM instances, then it does not 
make much of a sense to keep it. 

I request somebody to validate the study that i  did. 

I would have preferred, throwing a port conflict error rather than handling 
it and running the Server on some random port in the source code. 

The problem which it creates is, for a coder, if the server is started 
somehow, he assumes that the server is running on the same 9092 port and 
hence, he would connect to the same db on 9092 in all the instances, where 
he would have actually wanted to use a separate db instance running on a 
different port altogether. (unless, he goes and studies this source code).

Thanks
Vatsal
    

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to