## 5 IO Data Management and Data Sharing
### Distributed SQL Databases with RPC
#### 5.1.1. Replicated Data Bases and Tables  
Since a single SQL server is a critical central instance, preventing the appropriate scaling of parallel and distributed applications, the RPC-SQL API provides functions to copy entire tables by a single operation. Furthermore, those tables distributed on multiple SQL servers can be merged. ``` varsql1=DB.sql('ws://host:port:keya'), sql2=DB,sql('ws://host:port:keyb');sql1.copy('tablename',sql2)

#### 5.1.2 Capability Protection

The previously introduced capability mechanism is used to protect the SQL service, data bases, and, optionally, specific tables. The rights mask of the capability determines the allowed operations of the requesting worker process:

Reading tables and table rows. Modifying tables and modifying rows. Creation and deletion of tables. Creation and deletion of data bases. Alternatively, for the sake of simplicity and deployment in local networks, a simple string key can be provided that is always associated with the full rights mask. #### 5.1.3 Application Programming Interface

There is a unified data base module that can be used by any worker process to access remote data bases. The API provides one main function to create an access handle for a specific remote data base service by providing a valid URL with access capability. The access capability specifies the allowed operations on the data base. The handle provides functions to query the data base. A handle can switch between different data bases provided by the same service port, as shown in Example 7. **var** sql = **await** DB.sql(url,options)

**var** databaseList = **await** sql.databases()

**sql.open('mydatabase1')**

**var** tableList = **await** sql.tables()

**await** sql.create('mytable',{$colname:$type})

**await** sql.insert('mytable',{$colname:$data})

**var** rows = **await** sql.select('mytable',columns:string,where:string)

**await** sql.createDatabase('mydatabase2')

**await** sql.open('mydatabase2')

**await** sql.create('mytable2',{$colname:$type})

Example 7. Typical RPC-SQL access examples. The RPC-SQL service provides access to multiple data bases via one network port. Assuming sufficient client capabilities, new data bases can also be created remotely by a single operation. The newly created or opened data base can either be served by the same network port service or by creating a new service with a different network port on the fly. ### Shared Memory Segments and Buffer Objects

A shared memory segment (SMS) implements structured data with buffer objects (BO), creating shared buffer objects (SBO). The SMS provides linear memory management (linear memory block allocation and freeing), applied to the shared memory segment buffer. A buffer object is a proxy for scalar, array, or record-structured data. Each time a data element is accessed, the appropriate buffer handler operations transform high-level data access to low-level buffer operations, including the coding and decoding of data values with a linear memory model. SMS relies on \"SharedArrayBuffer\" objects in web workers and shared memory segments provided by the system-level OS in shell workers, respectively. A buffer object is stored in a region of the buffer segment that can be directly accessed by the high-level programming language via object monitors (proxies or getter/setter wrappers). Buffer objects are statically typified. Supported types are JS core data types (number, static strings, Boolean), C data size-constrained types (int8, int16, int32, float, double,... ), composed record data types (records), mono-typed and static-sized linear arrays, and matrix objects based on linear typed arrays. Finally, the SMS/BO implements shareable interprocess communication (IPC) objects, used for worker synchronization (on the same physical node):

* Mutex. * Semaphore. * Barrier. * Data queue (synchronization via two semaphores). The IPC objects use Atomics operations, applied to shared memory arrays (inside an SMS) to satisfy the inherent mutual exclusion.