* Sebastian Hammer, Adam Dickmeiss
*
* $Log: zserver.c,v $
- * Revision 1.26 1995-11-25 10:24:07 adam
+ * Revision 1.30 1995-12-07 17:38:48 adam
+ * Work locking mechanisms for concurrent updates/commit.
+ *
+ * Revision 1.29 1995/12/04 14:22:32 adam
+ * Extra arg to recType_byName.
+ * Started work on new regular expression parsed input to
+ * structured records.
+ *
+ * Revision 1.28 1995/11/28 09:09:48 adam
+ * Zebra config renamed.
+ * Use setting 'recordId' to identify record now.
+ * Bug fix in recindex.c: rec_release_blocks was invokeded even
+ * though the blocks were already released.
+ * File traversal properly deletes records when needed.
+ *
+ * Revision 1.27 1995/11/27 13:58:54 adam
+ * New option -t. storeStore data implemented in server.
+ *
+ * Revision 1.26 1995/11/25 10:24:07 adam
* More record fields - they are enumerated now.
* New options: flagStoreData flagStoreKey.
*
ZServerInfo server_info;
+static int register_check (ZServerInfo *zi)
+{
+ int state = zebraServerLockGetState();
+
+ switch (state)
+ {
+ case 'c':
+ state = 1;
+ break;
+ default:
+ state = 0;
+ }
+ if (zi->registerState == state)
+ return 0;
+
+ zi->registerState = state;
+ if (server_info.records)
+ {
+ dict_close (server_info.wordDict);
+ is_close (server_info.wordIsam);
+ rec_close (&server_info.records);
+ }
+ /* enable commit if state is 1 */
+ server_info.records = rec_open (0);
+ if (!(server_info.wordDict = dict_open (FNAME_WORD_DICT, 40, 0)))
+ return -1;
+ if (!(server_info.wordIsam = is_open (FNAME_WORD_ISAM, key_compare, 0,
+ sizeof (struct it_key))))
+ return -1;
+ return 0;
+}
+
bend_initresult *bend_init (bend_initrequest *q)
{
static bend_initresult r;
exit (1);
}
}
+ zebraServerLock ();
- data1_tabpath = res_get(common_resource, "data1_tabpath");
+ data1_tabpath = res_get(common_resource, "profilePath");
server_info.sets = NULL;
-
+ server_info.registerState = -1; /* trigger open of registers! */
+#if 1
+ server_info.records = NULL;
+ server_info.wordDict = NULL;
+ server_info.wordIsam = NULL;
+#else
server_info.records = rec_open (0);
if (!(server_info.wordDict = dict_open (FNAME_WORD_DICT, 40, 0)))
{
r.errstring = "is_open fail: word isam";
return &r;
}
+#endif
server_info.odr = odr_createmem (ODR_ENCODE);
return &r;
}
r.errstring = 0;
r.hits = 0;
-
+ register_check (&server_info);
odr_reset (server_info.odr);
server_info.errCode = 0;
server_info.errString = NULL;
return &r;
}
-static int record_read (int fd, char *buf, size_t count)
+static int record_ext_read (int fd, char *buf, size_t count)
{
return read (fd, buf, count);
}
+static int record_int_pos;
+static char *record_int_buf;
+static int record_int_len;
+
+static int record_int_read (int fd, char *buf, size_t count)
+{
+ int l = record_int_len - record_int_pos;
+ if (l <= 0)
+ return 0;
+ l = (l < count) ? l : count;
+ memcpy (buf, record_int_buf + record_int_pos, l);
+ record_int_pos += l;
+ return l;
+}
+
static int record_fetch (ZServerInfo *zi, int sysno, int score, ODR stream,
oid_value input_format, Z_RecordComposition *comp,
oid_value *output_format, char **rec_bufp,
char *fname, *file_type;
RecType rt;
struct recRetrieveCtrl retrieveCtrl;
+ char subType[128];
rec = rec_get (zi->records, sysno);
file_type = rec->info[recInfo_fileType];
fname = rec->info[recInfo_filename];
- if (!(rt = recType_byName (file_type)))
+ if (!(rt = recType_byName (file_type, subType)))
{
logf (LOG_FATAL|LOG_ERRNO, "Retrieve: Cannot handle type %s",
file_type);
exit (1);
}
logf (LOG_DEBUG, "retrieve localno=%d score=%d", sysno, score);
- if ((retrieveCtrl.fd = open (fname, O_RDONLY)) == -1)
+ if (rec->size[recInfo_storeData] > 0)
{
- char *msg = "Record doesn't exist";
- logf (LOG_WARN|LOG_ERRNO, "Retrieve: Open record file %s", fname);
- *output_format = VAL_SUTRS;
- *rec_bufp = msg;
- *rec_lenp = strlen (msg);
- rec_rm (&rec);
- return 0; /* or 14: System error in presenting records */
+ retrieveCtrl.readf = record_int_read;
+ record_int_len = rec->size[recInfo_storeData];
+ record_int_buf = rec->info[recInfo_storeData];
+ record_int_pos = 0;
+ logf (LOG_DEBUG, "Internal retrieve. %d bytes", record_int_len);
}
+ else
+ {
+ if ((retrieveCtrl.fd = open (fname, O_RDONLY)) == -1)
+ {
+ char *msg = "Record doesn't exist";
+ logf (LOG_WARN|LOG_ERRNO, "Retrieve: Open record file %s", fname);
+ *output_format = VAL_SUTRS;
+ *rec_bufp = msg;
+ *rec_lenp = strlen (msg);
+ rec_rm (&rec);
+ return 0; /* or 14: System error in presenting records */
+ }
+ retrieveCtrl.readf = record_ext_read;
+ }
+ retrieveCtrl.subType = subType;
retrieveCtrl.localno = sysno;
retrieveCtrl.score = score;
retrieveCtrl.odr = stream;
- retrieveCtrl.readf = record_read;
retrieveCtrl.input_format = retrieveCtrl.output_format = input_format;
retrieveCtrl.comp = comp;
retrieveCtrl.diagnostic = 0;
int positions[2];
ZServerSetSysno *records;
+ register_check (&server_info);
+
r.errstring = 0;
r.last_in_set = 0;
r.basename = "base";
bend_deleteresult *bend_delete (void *handle, bend_deleterequest *q, int *num)
{
+ register_check (&server_info);
return 0;
}
static bend_scanresult r;
int status;
+ register_check (&server_info);
odr_reset (server_info.odr);
server_info.errCode = 0;
server_info.errString = 0;
void bend_close (void *handle)
{
- dict_close (server_info.wordDict);
- is_close (server_info.wordIsam);
- rec_close (&server_info.records);
+ if (server_info.records)
+ {
+ dict_close (server_info.wordDict);
+ is_close (server_info.wordIsam);
+ rec_close (&server_info.records);
+ }
+ zebraServerUnlock ();
return;
}
struct statserv_options_block *sob;
sob = statserv_getcontrol ();
- strcpy (sob->configname, "base");
+ strcpy (sob->configname, FNAME_CONFIG);
statserv_setcontrol (sob);
return statserv_main (argc, argv);