+static int cf_commit_flat(CFile cf)
+{
+ zint *fp;
+ zint hno;
+ int i;
+ int r = 0;
+ zint vno = 0;
+
+#if CF_OPTIMIZE_COMMIT
+ struct map_cache *m_p;
+#endif
+
+
+#if CF_OPTIMIZE_COMMIT
+ m_p = map_cache_init (cf);
+#endif
+ fp = (zint *) xmalloc (HASH_BSIZE);
+ for (hno = cf->head.next_bucket; hno < cf->head.flat_bucket; hno++)
+ {
+ for (i = 0; i < (int) (HASH_BSIZE/sizeof(zint)); i++)
+ fp[i] = 0;
+ if (!mf_read (cf->hash_mf, hno, 0, 0, fp) &&
+ hno != cf->head.flat_bucket-1)
+ {
+ yaz_log (YLOG_FATAL, "read index block hno=" ZINT_FORMAT
+ " (" ZINT_FORMAT "-" ZINT_FORMAT ") commit",
+ hno, cf->head.next_bucket, cf->head.flat_bucket-1);
+ r = -1;
+ goto out;
+ }
+ for (i = 0; i < (int) (HASH_BSIZE/sizeof(zint)); i++)
+ {
+ if (fp[i])
+ {
+#if CF_OPTIMIZE_COMMIT
+ if (map_cache_add(m_p, fp[i], vno))
+ {
+ r = -1;
+ goto out;
+ }
+#else
+ if (mf_read (cf->block_mf, fp[i], 0, 0, cf->iobuf) != 1)
+ {
+ yaz_log (YLOG_FATAL, "read data block hno=" ZINT_FORMAT " (" ZINT_FORMAT "-" ZINT_FORMAT ") "
+ "i=%d commit block at " ZINT_FORMAT " (->" ZINT_FORMAT")",
+ hno, cf->head.next_bucket, cf->head.flat_bucket-1,
+ i, fp[i], vno);
+ r = -1;
+ goto out;
+ }
+ if (mf_write(cf->rmf, vno, 0, 0, cf->iobuf))
+ {
+ r = -1;
+ goto out;
+ }
+#endif
+ }
+ vno++;
+ }
+ }
+ out:
+#if CF_OPTIMIZE_COMMIT
+ if (map_cache_del(m_p))
+ r = -1;
+#endif
+ yaz_log(log_level, "cf_commit_flat r=%d", r);
+ xfree(fp);
+ return r;
+}
+
+int cf_commit(CFile cf)
+{
+ if (cf->bucket_in_memory)
+ {
+ yaz_log(YLOG_FATAL, "cf_commit: dirty cache");
+ return -1;
+ }
+ yaz_log(log_level, "cf_commit: state=%d", cf->head.state);
+ if (cf->head.state == CFILE_STATE_HASH)
+ return cf_commit_hash(cf);
+ else if (cf->head.state == CFILE_STATE_FLAT)
+ return cf_commit_flat(cf);
+ else
+ {
+ yaz_log(YLOG_FATAL, "cf_commit: bad state=%d", cf->head.state);
+ return -1;
+ }
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+