Beispiel #1
0
/*
 * disk_insert_instance - This inserts a new object in the database given a
 * "descriptor" for the object.
 *    return: NO_ERROR if successful, error code otherwise
 *    classop(in): class object
 *    obj(in): object description
 *    oid(in): oid of the destination
 */
int
disk_insert_instance (MOP classop, DESC_OBJ * obj, OID * oid)
{
  int error = NO_ERROR;
  HFID *hfid;
  int newsize;
  bool has_indexes;

  Diskrec->length = 0;
  if (desc_obj_to_disk (obj, Diskrec, &has_indexes))
    {
      /* make the record larger */
      newsize = -Diskrec->length + DB_PAGESIZE;
      free_recdes (Diskrec);
      Diskrec = alloc_recdes (newsize);
      /* try one more time */
      if (Diskrec == NULL || desc_obj_to_disk (obj, Diskrec, &has_indexes) != 0)
	{
	  error = ER_LDR_CANT_TRANSFORM;
	  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
	}
    }

  if (!error)
    {
      hfid = get_class_heap (classop, obj->class_);
      if (hfid == NULL)
	{
	  assert (er_errid () != NO_ERROR);
	  error = er_errid ();
	}
      else
	{
	  HEAP_OPERATION_CONTEXT context;

	  /* set up context */
	  heap_create_insert_context (&context, hfid, WS_OID (classop), Diskrec, NULL, false);

	  /* oid is set here as a side effect */
	  if (heap_insert_logical (NULL, &context) != NO_ERROR)
	    {
	      assert (er_errid () != NO_ERROR);
	      error = er_errid ();
	    }
	  else if (has_indexes)
	    {
	      COPY_OID (oid, &context.res_oid);
	      error = update_indexes (WS_OID (classop), oid, Diskrec);
	    }
	  else
	    {
	      COPY_OID (oid, &context.res_oid);
	    }
	}
    }
  return (error);
}
Beispiel #2
0
/*
 * disk_update_instance - This updates an object that had previously been
 * reserved with the actual contents.
 *    return: NO_ERROR if successful, error code otherwise
 *    classop(in): class object
 *    obj(in): description of object
 *    oid(in): destination oid
 */
int
disk_update_instance (MOP classop, DESC_OBJ * obj, OID * oid)
{
  int error = NO_ERROR;
  HFID *hfid;
  int newsize;
  bool has_indexes = false;

  Diskrec->length = 0;
  if (desc_obj_to_disk (obj, Diskrec, &has_indexes))
    {
      /* make the record larger */
      newsize = -Diskrec->length + DB_PAGESIZE;
      free_recdes (Diskrec);
      Diskrec = alloc_recdes (newsize);
      /* try one more time */
      if (Diskrec == NULL || desc_obj_to_disk (obj, Diskrec, &has_indexes) != 0)
	{
	  error = ER_LDR_CANT_TRANSFORM;
	  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
	}
    }
  if (!error)
    {
      hfid = get_class_heap (classop, obj->class_);
      if (hfid == NULL)
	{
	  assert (er_errid () != NO_ERROR);
	  error = er_errid ();
	}
      else
	{
	  HEAP_OPERATION_CONTEXT update_context;

	  heap_create_update_context (&update_context, hfid, oid, WS_OID (classop), Diskrec, NULL, UPDATE_INPLACE_NONE);

	  if (heap_update_logical (NULL, &update_context) != NO_ERROR)
	    {
	      assert (er_errid () != NO_ERROR);
	      error = er_errid ();
	    }

	  if (update_context.is_logical_old)
	    {
	      fprintf (stdout,
		       msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_UPDATE_WARNING));
	    }
	  else if (has_indexes)
	    {
	      error = update_indexes (WS_OID (classop), oid, Diskrec);
	    }
	}
    }

  return (error);
}
Beispiel #3
0
/*
 * disk_update_instance - This updates an object that had previously been
 * reserved with the acutal contents.
 *    return: NO_ERROR if successful, error code otherwise
 *    classop(in): class object
 *    obj(in): description of object
 *    oid(in): destination oid
 */
int
disk_update_instance (MOP classop, DESC_OBJ * obj, OID * oid)
{
  int error = NO_ERROR;
  HFID *hfid;
  int newsize;
  bool has_indexes = false, oldflag;

  Diskrec->length = 0;
  if (desc_obj_to_disk (obj, Diskrec, &has_indexes))
    {
      /* make the record larger */
      newsize = -Diskrec->length + DB_PAGESIZE;
      free_recdes (Diskrec);
      Diskrec = alloc_recdes (newsize);
      /* try one more time */
      if (Diskrec == NULL
	  || desc_obj_to_disk (obj, Diskrec, &has_indexes) != 0)
	{
	  error = ER_LDR_CANT_TRANSFORM;
	  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
	}
    }
  if (!error)
    {
      hfid = get_class_heap (classop, obj->class_);
      if (hfid == NULL)
	{
	  error = er_errid ();
	}
      else if (heap_update (NULL, hfid, oid, Diskrec, &oldflag, NULL) != oid)
	{
	  error = er_errid ();
	}
      else
	{
	  if (oldflag)
	    {
	      fprintf (stdout, msgcat_message (MSGCAT_CATALOG_UTILS,
					       MSGCAT_UTIL_SET_LOADDB,
					       LOADDB_MSG_UPDATE_WARNING));
	    }
	  else if (has_indexes)
	    {
	      error = update_indexes (WS_OID (classop), oid, Diskrec);
	    }
	}
    }

  return (error);
}
Beispiel #4
0
LIBCOUCHSTORE_API
couchstore_error_t couchstore_save_documents(Db *db,
                                             Doc* const docs[],
                                             DocInfo *infos[],
                                             unsigned numdocs,
                                             couchstore_save_options options)
{
    couchstore_error_t errcode = COUCHSTORE_SUCCESS;
    unsigned ii;
    sized_buf *seqklist, *idklist, *seqvlist, *idvlist;
    size_t term_meta_size = 0;
    const Doc *curdoc;
    uint64_t seq = db->header.update_seq;

    fatbuf *fb;
    
    for (ii = 0; ii < numdocs; ii++) {
        // Get additional size for terms to be inserted into indexes
        // IMPORTANT: This must match the sizes of the fatbuf_get calls in add_doc_to_update_list!
        term_meta_size += 6
                        + 44 + infos[ii]->id.size + infos[ii]->rev_meta.size
                        + 44 + 10 + infos[ii]->rev_meta.size;
    }

    fb = fatbuf_alloc(term_meta_size +
                      numdocs * (sizeof(sized_buf) * 4)); //seq/id key and value lists

    if (fb == NULL) {
        return COUCHSTORE_ERROR_ALLOC_FAIL;
    }


    seqklist = fatbuf_get(fb, numdocs * sizeof(sized_buf));
    idklist = fatbuf_get(fb, numdocs * sizeof(sized_buf));
    seqvlist = fatbuf_get(fb, numdocs * sizeof(sized_buf));
    idvlist = fatbuf_get(fb, numdocs * sizeof(sized_buf));

    for (ii = 0; ii < numdocs; ii++) {
        seq++;
        if (docs) {
            curdoc = docs[ii];
        } else {
            curdoc = NULL;
        }

        errcode = add_doc_to_update_list(db, curdoc, infos[ii], fb,
                                         &seqklist[ii], &idklist[ii],
                                         &seqvlist[ii], &idvlist[ii],
                                         seq, options);
        if (errcode != COUCHSTORE_SUCCESS) {
            break;
        }
    }

    if (errcode == COUCHSTORE_SUCCESS) {
        errcode = update_indexes(db, seqklist, seqvlist,
                                 idklist, idvlist, numdocs);
    }

    fatbuf_free(fb);
    if (errcode == COUCHSTORE_SUCCESS) {
        // Fill in the assigned sequence numbers for caller's later use:
        seq = db->header.update_seq;
        for (ii = 0; ii < numdocs; ii++) {
            infos[ii]->db_seq = ++seq;
        }
        db->header.update_seq = seq;
    }

    return errcode;
}
Beispiel #5
0
/*
 * disk_update_instance_using_mobj - updates an object that had previously
 * been reserved with the acutal contents.
 *    return: NO_ERROR if successful, error code otherwise
 *    classop(in): class object
 *    classobj(in): class memory object
 *    obj(in): object memory.
 *    oid(in): oid of the destination
 */
int
disk_update_instance_using_mobj (MOP classop, MOBJ classobj,
				 MOBJ obj, OID * oid)
{
  int error = NO_ERROR;
  HFID *hfid;
  bool has_indexes = false;
  volatile int newsize = 0;
  bool oldflag;
  TF_STATUS tf_status = TF_SUCCESS;

  Diskrec->length = 0;
  /*
   * tf_mem_to_disk() is used to get an estimate of the disk space requirements
   * for the object. When dealing with collections the estimate returned is
   * not always a good one, hence we need to enclose this block in a loop
   * increasing the space by increments of DB_PAGESIZE until we hit the correct
   * space requirement.
   */
  while ((tf_status =
	  tf_mem_to_disk (classop, classobj, obj, Diskrec,
			  &has_indexes)) == TF_OUT_OF_SPACE)
    {
      /* make the record larger */
      if (newsize)
	{
	  newsize += DB_PAGESIZE;
	}
      else
	{
	  newsize = -Diskrec->length + DB_PAGESIZE;
	}
      free_recdes (Diskrec);
      Diskrec = alloc_recdes (newsize);
      if (Diskrec == NULL)
	{
	  error = er_errid ();
	  break;
	}
    }
  if (tf_status != TF_SUCCESS)
    {
      error = ER_LDR_CANT_TRANSFORM;
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
    }
  if (error == NO_ERROR && Diskrec != NULL)
    {
      hfid = get_class_heap (classop, (SM_CLASS *) classop->object);
      if (hfid == NULL)
	{
	  error = er_errid ();
	}
      else if (heap_update (NULL, hfid, oid, Diskrec, &oldflag, NULL) != oid)
	{
	  error = er_errid ();
	}
      else
	{
	  if (oldflag)
	    {
	      fprintf (stdout, msgcat_message (MSGCAT_CATALOG_UTILS,
					       MSGCAT_UTIL_SET_LOADDB,
					       LOADDB_MSG_UPDATE_WARNING));
	    }
	  else if (has_indexes)
	    {
	      error = update_indexes (WS_OID (classop), oid, Diskrec);
	    }
	}
    }

  return (error);
}
Beispiel #6
0
/*
 * disk_insert_instance_using_mobj - inserts a new object in the database
 * given a memory object and class object
 *    return: NO_ERROR if successful, error code otherwise
 *    classop(in): class object
 *    classobj(in): class memory object
 *    obj(in): object memory.
 *    oid(out): oid of the destination
 */
int
disk_insert_instance_using_mobj (MOP classop, MOBJ classobj, MOBJ obj, OID * oid)
{
  int error = NO_ERROR;
  HFID *hfid;
  volatile int newsize = 0;
  bool has_indexes;
  TF_STATUS tf_status = TF_SUCCESS;

  Diskrec->length = 0;

  /* 
   * tf_mem_to_disk() is used to get an estimate of the disk space requirements
   * for the object. When dealing with collections the estimate returned is
   * not always a good one, hence we need to enclose this block in a loop
   * increasing the space by increments of DB_PAGESIZE until we hit the correct
   * space requirement.
   */
  while ((tf_status = tf_mem_to_disk (classop, classobj, obj, Diskrec, &has_indexes)) == TF_OUT_OF_SPACE)
    {
      /* make the record larger */
      if (newsize)
	{
	  newsize += DB_PAGESIZE;
	}
      else
	{
	  newsize = -Diskrec->length + DB_PAGESIZE;
	}
      free_recdes (Diskrec);
      Diskrec = alloc_recdes (newsize);
      if (Diskrec == NULL)
	{
	  assert (er_errid () != NO_ERROR);
	  error = er_errid ();
	  break;
	}
    }
  if (tf_status != TF_SUCCESS)
    {
      error = ER_LDR_CANT_TRANSFORM;
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
    }

  if (error == NO_ERROR && Diskrec != NULL)
    {
      hfid = get_class_heap (classop, (SM_CLASS *) classop->object);
      if (hfid == NULL)
	{
	  assert (er_errid () != NO_ERROR);
	  error = er_errid ();
	}
      else
	{
	  HEAP_OPERATION_CONTEXT context;

	  /* set up context */
	  heap_create_insert_context (&context, hfid, WS_OID (classop), Diskrec, NULL);

	  /* oid is set here as a side effect */
	  if (heap_insert_logical (NULL, &context) != NO_ERROR)
	    {
	      assert (er_errid () != NO_ERROR);
	      error = er_errid ();
	    }
	  else if (has_indexes)
	    {
	      COPY_OID (oid, &context.res_oid);
	      error = update_indexes (WS_OID (classop), oid, Diskrec);
	    }
	  else
	    {
	      COPY_OID (oid, &context.res_oid);
	    }
	}
    }
  return (error);
}