Browse Source

ckdb/sql - add sql/code definition for Marks - not implemented yet

master
kanoi 10 years ago
parent
commit
71eac4e579
  1. 19
      sql/ckdb.sql
  2. 41
      sql/v0.9.4-v0.9.5.sql
  3. 5
      src/ckdb.c
  4. 54
      src/ckdb.h

19
sql/ckdb.sql

@ -251,6 +251,21 @@ CREATE TABLE sharesummary ( -- per workinfo for each user+worker
);
CREATE TABLE marks ( -- workinfoids to make workmarkers
poolinstance character varying(256) NOT NULL,
workinfoid bigint NOT NULL,
description character varying(256) DEFAULT ''::character varying NOT NULL,
marktype char NOT NULL, -- 'b'lock 'p'plns-begin 's'hift-begin 'e'=shift-end
status char NOT NULL,
createdate timestamp with time zone NOT NULL,
createby character varying(64) DEFAULT ''::character varying NOT NULL,
createcode character varying(128) DEFAULT ''::character varying NOT NULL,
createinet character varying(128) DEFAULT ''::character varying NOT NULL,
expirydate timestamp with time zone DEFAULT '6666-06-06 06:06:06+00',
PRIMARY KEY (poolinstance, workinfoid, expirydate)
);
CREATE TABLE workmarkers ( -- range of workinfo for share accounting
markerid bigint NOT NULL,
poolinstance character varying(256) NOT NULL,
@ -263,7 +278,7 @@ CREATE TABLE workmarkers ( -- range of workinfo for share accounting
createcode character varying(128) DEFAULT ''::character varying NOT NULL,
createinet character varying(128) DEFAULT ''::character varying NOT NULL,
expirydate timestamp with time zone DEFAULT '6666-06-06 06:06:06+00',
PRIMARY KEY (markerid)
PRIMARY KEY (markerid, expirydate)
);
@ -417,4 +432,4 @@ CREATE TABLE version (
PRIMARY KEY (vlock)
);
insert into version (vlock,version) values (1,'0.9.4');
insert into version (vlock,version) values (1,'0.9.5');

41
sql/v0.9.4-v0.9.5.sql

@ -0,0 +1,41 @@
SET SESSION AUTHORIZATION 'postgres';
BEGIN transaction;
DO $$
DECLARE ver TEXT;
BEGIN
UPDATE version set version='0.9.5' where vlock=1 and version='0.9.4';
IF found THEN
RETURN;
END IF;
SELECT version into ver from version
WHERE vlock=1;
RAISE EXCEPTION 'Wrong DB version - expect "0.9.4" - found "%"', ver;
END $$;
CREATE TABLE marks ( -- workinfoids to make workmarkers
poolinstance character varying(256) NOT NULL,
workinfoid bigint NOT NULL,
description character varying(256) DEFAULT ''::character varying NOT NULL,
marktype char NOT NULL, -- 'b'lock(end) 'p'plns-begin 's'hift-begin 'e'=shift-end
status char NOT NULL,
createdate timestamp with time zone NOT NULL,
createby character varying(64) DEFAULT ''::character varying NOT NULL,
createcode character varying(128) DEFAULT ''::character varying NOT NULL,
createinet character varying(128) DEFAULT ''::character varying NOT NULL,
expirydate timestamp with time zone DEFAULT '6666-06-06 06:06:06+00',
PRIMARY KEY (poolinstance, workinfoid, expirydate)
);
ALTER TABLE workmarkers DROP CONSTRAINT workmarkers_pkey;
ALTER TABLE workmarkers ADD CONSTRAINT workmarkers_pkey
PRIMARY KEY (markerid, expirydate);
END transaction;

5
src/ckdb.c

@ -453,6 +453,11 @@ K_TREE *workmarkers_workinfoid_root;
K_LIST *workmarkers_free;
K_STORE *workmarkers_store;
// MARKS
K_TREE *marks_root;
K_LIST *marks_free;
K_STORE *marks_store;
static char logname[512];
static char *dbcode;

54
src/ckdb.h

@ -51,7 +51,7 @@
*/
#define DB_VLOCK "1"
#define DB_VERSION "0.9.4"
#define DB_VERSION "0.9.5"
#define CKDB_VERSION DB_VERSION"-0.646"
#define WHERE_FFL " - from %s %s() line %d"
@ -1333,6 +1333,58 @@ extern K_STORE *workmarkers_store;
#define MARKER_COMPLETE 'x'
#define WMREADY(_status) (tolower(_status[0]) == MARKER_COMPLETE)
// MARKS
// TODO: implement
typedef struct marks {
char *poolinstance;
int64_t workinfoid;
char *description;
char marktype[TXT_FLAG+1];
char status[TXT_FLAG+1];
HISTORYDATECONTROLFIELDS;
} MARKS;
/* Marks:
* marktype is one of:
* b - block end
* p - pplns begin
* s - shift begin (not yet used)
* e - shift end (not yet used)
* description should one one of
* b - Block NNN stt
* p - Payout NNN fin (where NNN is the block number of the payout)
* s/e - to be decided
*
* WorkMarkers are from a begin workinfoid to an end workinfoid
* the "-1" and "+1" below mean adding to or subtracting from
* the workinfoid number
*
* Until we start using shifts:
* WorkMarkers can be created up to ending in the largest 'p' "-1"
* WorkMarkers will always be the smallest of:
* Block NNN-1 "+1" to Block NNN
* Block NNN "+1" to Payout MMM "-1"
* Payout MMM to Block NNN
* Payout MMM-1 to Payout MMM "-1"
* Thus to generate the WorkMarkers from the Marks:
* Find the last 'p' with no matching workinfoidbegin
* Then determine each previous WorkMarker based on each previous
* mark, using the above rules and stop when we find one that already exists
*/
#define ALLOC_MARKS 1000
#define LIMIT_MARKS 0
#define INIT_MARKS(_item) INIT_GENERIC(_item, marks)
#define DATA_MARKS(_var, _item) DATA_GENERIC(_var, _item, marks, true)
#define DATA_MARKS_NULL(_var, _item) DATA_GENERIC(_var, _item, marks, false)
extern K_TREE *marks_root;
extern K_LIST *marks_free;
extern K_STORE *marks_store;
#define MARK_READY 'x'
#define MREADY(_status) (tolower(_status[0]) == MARK_READY)
extern void logmsg(int loglevel, const char *fmt, ...);
extern void setnow(tv_t *now);
extern void tick();

Loading…
Cancel
Save