{"id":2308,"date":"2013-11-11T20:06:45","date_gmt":"2013-11-12T01:06:45","guid":{"rendered":"http:\/\/hstore.cs.brown.edu\/?page_id=2308"},"modified":"2013-11-11T21:01:00","modified_gmt":"2013-11-12T02:01:00","slug":"new-system-stored-procedures","status":"publish","type":"page","link":"https:\/\/hstore.cs.brown.edu\/documentation\/development\/new-system-stored-procedures\/","title":{"rendered":"Writing New System Stored Procedures"},"content":{"rendered":"

\u00ab<\/B> Writing New Tests<\/a><\/div>
Internal Catalog Schema<\/a> \u00bb<\/B><\/div>
<\/div><\/p>\n

The following page describes how to create a new system stored procedure in H-Store. System stored procedures (“sysprocs”) are special transactions that perform some administrative operation (e.g., invoking the JVM’s garbage collector, retrieving internal statistics).<\/p>\n

A sysproc generally consists of two phases. In the first phase, the system will execute some operation at every partition in the cluster and generate some intermediate output (DISTRIBUTE). Then in the second phase, the transaction’s base partition will combine the output from each partition into a single output result that is returned to the client (AGGREGATE). Sysprocs transactions are not included in the the command log<\/a>, thus any changes they may make to the database are not durable (excluding @LoadMultipartitionTable<\/a>).<\/p>\n

In this page, we will create a new sysproc called @ToneLoc<\/tt> that will generate an output table with the current time at each node.<\/p>\n

Adding PlanFragment Ids<\/h2>\n

Before you will create the class for your new sysproc, you first need to add in unique identifiers for synthetic PlanFragments that will be used to denote which phase the transaction is in. Add two new entries to SysProcFragmentId<\/a>:<\/p>\n\n

\/\/ @ToneLoc<\/span>\npublic<\/span> static<\/span> final<\/span> int<\/span> PF_ToneLocDistribute =<\/span> 310<\/span>;<\/span>\npublic<\/span> static<\/span> final<\/span> int<\/span> PF_ToneLocAggregate =<\/span> 311<\/span>;<\/span><\/pre><\/td><\/tr><\/table><\/div>\n\n

Note that the fragment ids used in the new entry must be different from all the other entries in SysProcFragmentId<\/tt><\/p>\n

Creating Procedure Class<\/h2>\n

Create a new class file in the src\/frontend\/org\/voltdb\/sysprocs<\/a> directory. This new class needs to extend the VoltSystemProcedure<\/a> class. The new class needs to implement three methods:<\/p>\n