smalltalk programming for the web

GOODS OODB on Unix Domain Sockets

28 July 2013

GOODS "is an object oriented fully distrbuted database management system using an active client model." It is also described as a "language-neutral object database" with client interfaces for C++, Java and Perl. GOODS is written by Konstantin Knizhnik.

Avi Bryant developed a Squeak client for GOODS that allows transparent storage of Smalltalk objects. The client is now maintained for Pharo, Squeak and VisualWorks by David Shaffer and is hosted on SqueakSource3.

GOODS works over TCP and Unix domain sockets. However, the GOODS documentation doesn't actually describe how to configure for the latter. There is, however, a hint in the main configuration file "goodsrv.cfg":

# Enable or disable acceptance of remote connections by GOODS server. 
# Disabling remote connections avoid any problem with firewall. In this case
# GOODS server is able to handle only local connections (Unix socket, Win32 local socket, process socket) 
server.remote.connections=1 # 1 or 0

In addition to the main configuration file, there is database-specific configuration file, which I've named "test.cfg", that looks like this:


This matches the configuration format:

<number of storages = N>
<storage identifier 0>: <hostname>:<port>

Meaning, for test.cfg, I'm specifying one storage server, and it listens on TCP port 60060 on localhost.

But what about the Unix domain socket path? To find out, I set the server.remote.connections parameter to 0 and try it out:

% goodsrv test 0 -
Read the whole database size to page pool
16:52.59 28-JUL-2013: Checkpoint 37 finished
GOODS server started...
server is up...

What happened? Looking around, it is found that GOODS has created a Unix domain socket at "/tmp/localhost:60060". Yes, ":60060" is part of the socket's path name. Cute. Trying to use a more descriptive name like "goodsock" or whatever fails with "bad address". Hitting the GOODS source, unisock.cxx shows that that unix_socket_dir is hardcoded to "/tmp/", and that the file name format has to be "string:number".

Oh well. I've abstracted the procedure to obtain a Unix domain socket address from a path string from my previous post as follows:

NetNameResolver class>>addressForSocketPath: socketPath
  | size sa |

  NetNameResolver primGetAddressInfoHost: '' service: socketPath flags: 0 family: 1 type: 0 protocol: 0.
  size := NetNameResolver primGetAddressInfoSize.
  sa := SocketAddress new: size withAll: 0.
  NetNameResolver primGetAddressInfoResult: sa.
  ^ sa

However, asking for a Unix domain socket address for "/tmp/localhost:60060" causes primGetAddressInfoHost:blah:blah: to fail. Bummer.

Okay, it is easier to modify GOODS since I've been browsing its source, then to get well-acquainted with SocketPlugin. So, at line 107 of unisock.cxx, make this change:

//sprintf( + offsetof(sockaddr,sa_data), "%s%s", unix_socket_dir, address);
sprintf( + offsetof(sockaddr,sa_data), "%s%s", unix_socket_dir, hostname);

The commented out line is the original. "hostname" is "address" minus the colon and port number that comes after it.

Rebuild GOODS, change the path in test.cfg to say "goodserver:60060", restart, and we see that the Unix domain socket is now called "/tmp/goodserver" and "NetNameResolver addressForSocketPath: '/tmp/goodserver'" duly returns a SocketAddress instance.

Next, load the Squeak/Pharo GOODS client from SS3. Subclass KKSqueakTCPSocketTransport as KKPharoIPCSocketTransport, with the single method:

KKPharoIPCSocketTransport>>initializeSocketAddress: aSocketPath
  "Create and connect to specified Unix domain socket address."

  socket := Socket newIPC connectTo: (NetNameResolver addressForSocketPath: aSocketPath).
  (Delay forMilliseconds: 10) wait.

Some other corresponding modifications are needed, such as in KKDatabase and KKConnection. Finally, in workspace, run this:

| db |
KKDatabase defaultTransportClass: KKPharoIPCSocketTransport.
db := KKDatabase onSocketPath: '/tmp/goodserver'.
db root: Dictionary new.
db commit.
db explore.

And it works!

% goodsrv test 0 -
Read the whole database size to page pool
17:32.38 28-JUL-2013: Checkpoint 45 finished
GOODS server started...
server is up...
17:32.44 28-JUL-2013: Open session for client 'squeak16r38E5541'
Send class 'Dictionary' to client

Running "self logout" in the KKDatabase instance explorer from above results in additional output from GOODS:

17:39.23 28-JUL-2013: Client 'squeak16r38E5541' send logout request
17:39.23 28-JUL-2013: Disconnect 'squeak16r38E5541'
Server agent 'squeak16r38E5541' terminated