Exemple #1
0
/*
 * db_ws_realloc () - call re-allocation function for the lea heap
 *   return: allocated memory pointer
 *   size(in): size to allocate
 */
void *
db_ws_realloc (void *ptr, size_t size)
{
#if defined(SA_MODE)
  if (ptr == NULL)
    {
      return db_ws_alloc (size);
    }

  if (ws_heap_id && size > 0)
    {
      PRIVATE_MALLOC_HEADER *h;

      h = private_user2hl_ptr (ptr);
      if (h->magic != PRIVATE_MALLOC_HEADER_MAGIC)
	{
	  return NULL;
	}

      if (h->alloc_type == PRIVATE_ALLOC_TYPE_WS)
	{
	  PRIVATE_MALLOC_HEADER *new_h;
	  size_t req_sz;

	  req_sz = private_request_size (size);
	  new_h = hl_lea_realloc (ws_heap_id, h, req_sz);
	  if (new_h == NULL)
	    {
	      return NULL;
	    }
	  return private_hl2user_ptr (new_h);
	}
      else if (h->alloc_type == PRIVATE_ALLOC_TYPE_LEA)
	{
	  return db_private_realloc (NULL, ptr, size);
	}
      else
	{
	  return NULL;
	}
    }
  else
    {
      return NULL;
    }
#else
  if (ws_heap_id && (size > 0))
    {
      ptr = hl_lea_realloc (ws_heap_id, ptr, size);
    }
  return ptr;
#endif
}
Exemple #2
0
/*
 * qst_client_unpack_statistics () - Unpack the buffer containing statistics
 *   return: CLASS_STATS or NULL in case of error
 *   bufp(in): buffer containing the class statistics
 *
 * Note: This function unpacks the statistics on the buffer received from the
 *       server side, and builds a CLASS_STATS structure on the work space
 *       area. This sturucture is returned to the caller.
 */
static CLASS_STATS *
stats_client_unpack_statistics (char *buf_p)
{
  CLASS_STATS *class_stats_p;
  ATTR_STATS *attr_stats_p;
  BTREE_STATS *btree_stats_p;
  int i, j, k;

  if (!buf_p)
    {
      return NULL;
    }

  class_stats_p = (CLASS_STATS *) db_ws_alloc (sizeof (CLASS_STATS));
  if (!class_stats_p)
    {
      return NULL;
    }

  class_stats_p->time_stamp = (unsigned int) OR_GET_INT (buf_p);
  buf_p += OR_INT_SIZE;

  class_stats_p->num_objects = OR_GET_INT (buf_p);
  buf_p += OR_INT_SIZE;

  class_stats_p->heap_size = OR_GET_INT (buf_p);
  buf_p += OR_INT_SIZE;

  class_stats_p->n_attrs = OR_GET_INT (buf_p);
  buf_p += OR_INT_SIZE;

  if (class_stats_p->n_attrs == 0)
    {
      db_ws_free (class_stats_p);
      return NULL;
    }

  class_stats_p->attr_stats =
    (ATTR_STATS *) db_ws_alloc (class_stats_p->n_attrs * sizeof (ATTR_STATS));
  if (!class_stats_p->attr_stats)
    {
      db_ws_free (class_stats_p);
      return NULL;
    }

  for (i = 0, attr_stats_p = class_stats_p->attr_stats;
       i < class_stats_p->n_attrs; i++, attr_stats_p++)
    {

      attr_stats_p->id = OR_GET_INT (buf_p);
      buf_p += OR_INT_SIZE;

      attr_stats_p->type = (DB_TYPE) OR_GET_INT (buf_p);
      buf_p += OR_INT_SIZE;

      switch (attr_stats_p->type)
	{
	case DB_TYPE_INTEGER:
	  attr_stats_p->min_value.i = OR_GET_INT (buf_p);
	  buf_p += STATS_MIN_MAX_SIZE;
	  attr_stats_p->max_value.i = OR_GET_INT (buf_p);
	  buf_p += STATS_MIN_MAX_SIZE;
	  break;

	case DB_TYPE_BIGINT:
	  attr_stats_p->min_value.bigint = OR_GET_BIGINT (buf_p);
	  buf_p += STATS_MIN_MAX_SIZE;
	  attr_stats_p->max_value.bigint = OR_GET_BIGINT (buf_p);
	  buf_p += STATS_MIN_MAX_SIZE;
	  break;

	case DB_TYPE_SHORT:
	  /* stored these as full integers because of alignment */
	  attr_stats_p->min_value.i = OR_GET_INT (buf_p);
	  buf_p += STATS_MIN_MAX_SIZE;
	  attr_stats_p->max_value.i = OR_GET_INT (buf_p);
	  buf_p += STATS_MIN_MAX_SIZE;
	  break;

	case DB_TYPE_FLOAT:
	  OR_GET_FLOAT (buf_p, &(attr_stats_p->min_value.f));
	  buf_p += STATS_MIN_MAX_SIZE;
	  OR_GET_FLOAT (buf_p, &(attr_stats_p->max_value.f));
	  buf_p += STATS_MIN_MAX_SIZE;
	  break;

	case DB_TYPE_DOUBLE:
	  OR_GET_DOUBLE (buf_p, &(attr_stats_p->min_value.d));
	  buf_p += STATS_MIN_MAX_SIZE;
	  OR_GET_DOUBLE (buf_p, &(attr_stats_p->max_value.d));
	  buf_p += STATS_MIN_MAX_SIZE;
	  break;

	case DB_TYPE_DATE:
	  OR_GET_DATE (buf_p, &(attr_stats_p->min_value.date));
	  buf_p += STATS_MIN_MAX_SIZE;
	  OR_GET_DATE (buf_p, &(attr_stats_p->max_value.date));
	  buf_p += STATS_MIN_MAX_SIZE;
	  break;

	case DB_TYPE_TIME:
	  OR_GET_TIME (buf_p, &(attr_stats_p->min_value.time));
	  buf_p += STATS_MIN_MAX_SIZE;
	  OR_GET_TIME (buf_p, &(attr_stats_p->max_value.time));
	  buf_p += STATS_MIN_MAX_SIZE;
	  break;

	case DB_TYPE_UTIME:
	  OR_GET_UTIME (buf_p, &(attr_stats_p->min_value.utime));
	  buf_p += STATS_MIN_MAX_SIZE;
	  OR_GET_UTIME (buf_p, &(attr_stats_p->max_value.utime));
	  buf_p += STATS_MIN_MAX_SIZE;
	  break;

	case DB_TYPE_DATETIME:
	  OR_GET_DATETIME (buf_p, &(attr_stats_p->min_value.datetime));
	  buf_p += STATS_MIN_MAX_SIZE;
	  OR_GET_DATETIME (buf_p, &(attr_stats_p->max_value.datetime));
	  buf_p += STATS_MIN_MAX_SIZE;
	  break;

	case DB_TYPE_MONETARY:
	  OR_GET_MONETARY (buf_p, &(attr_stats_p->min_value.money));
	  buf_p += STATS_MIN_MAX_SIZE;
	  OR_GET_MONETARY (buf_p, &(attr_stats_p->max_value.money));
	  buf_p += STATS_MIN_MAX_SIZE;
	  break;

	default:
	  break;
	}

      attr_stats_p->n_btstats = OR_GET_INT (buf_p);
      buf_p += OR_INT_SIZE;

      if (attr_stats_p->n_btstats <= 0)
	{
	  attr_stats_p->bt_stats = NULL;
	  continue;
	}

      attr_stats_p->bt_stats =
	(BTREE_STATS *) db_ws_alloc (attr_stats_p->n_btstats *
				     sizeof (BTREE_STATS));
      if (!attr_stats_p->bt_stats)
	{
	  stats_free_statistics (class_stats_p);
	  return NULL;
	}

      for (j = 0, btree_stats_p = attr_stats_p->bt_stats;
	   j < attr_stats_p->n_btstats; j++, btree_stats_p++)
	{
	  OR_GET_BTID (buf_p, &btree_stats_p->btid);
	  buf_p += OR_BTID_ALIGNED_SIZE;

	  btree_stats_p->leafs = OR_GET_INT (buf_p);
	  buf_p += OR_INT_SIZE;

	  btree_stats_p->pages = OR_GET_INT (buf_p);
	  buf_p += OR_INT_SIZE;

	  btree_stats_p->height = OR_GET_INT (buf_p);
	  buf_p += OR_INT_SIZE;

	  btree_stats_p->keys = OR_GET_INT (buf_p);
	  buf_p += OR_INT_SIZE;

	  btree_stats_p->oids = OR_GET_INT (buf_p);
	  buf_p += OR_INT_SIZE;

	  btree_stats_p->nulls = OR_GET_INT (buf_p);
	  buf_p += OR_INT_SIZE;

	  btree_stats_p->ukeys = OR_GET_INT (buf_p);
	  buf_p += OR_INT_SIZE;

	  buf_p = or_unpack_domain (buf_p, &btree_stats_p->key_type, 0);

	  if (btree_stats_p->key_type != NULL
	      && btree_stats_p->key_type->type->id == DB_TYPE_MIDXKEY)
	    {
	      btree_stats_p->key_size =
		tp_domain_size (btree_stats_p->key_type->setdomain);
	    }
	  else
	    {
	      btree_stats_p->key_size = 1;
	    }

	  btree_stats_p->pkeys =
	    (int *) db_ws_alloc (btree_stats_p->key_size * sizeof (int));
	  if (!btree_stats_p->pkeys)
	    {
	      stats_free_statistics (class_stats_p);
	      return NULL;
	    }

	  for (k = 0; k < btree_stats_p->key_size; k++)
	    {
	      btree_stats_p->pkeys[k] = OR_GET_INT (buf_p);
	      buf_p += OR_INT_SIZE;
	    }
	}
    }

  return class_stats_p;
}
Exemple #3
0
/*
 * db_private_alloc () - call allocation function for current private heap
 *   return: allocated memory pointer
 *   thrd(in): thread conext if it is server, otherwise NULL
 *   size(in): size to allocate
 */
void *
db_private_alloc (void *thrd, size_t size)
{
  void *ptr = NULL;

#if defined (CS_MODE)
  return db_ws_alloc (size);
#elif defined (SERVER_MODE)
  HL_HEAPID heap_id;

  if (size <= 0)
    {
      return NULL;
    }

  heap_id = (thrd ? ((THREAD_ENTRY *) thrd)->private_heap_id :
	     css_get_private_heap (NULL));

  if (heap_id)
    {
      ptr = hl_lea_alloc (heap_id, size);
    }
  else
    {
      ptr = malloc (size);
      if (ptr == NULL)
	{
	  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY,
		  1, size);
	}
    }
  return ptr;
#else /* SA_MODE */
  if (!db_on_server)
    {
      return db_ws_alloc (size);
    }
  else
    {
      if (size <= 0)
	{
	  return NULL;
	}

      if (private_heap_id)
	{
	  PRIVATE_MALLOC_HEADER *h = NULL;
	  size_t req_sz;

	  req_sz = private_request_size (size);
	  h = hl_lea_alloc (private_heap_id, req_sz);

	  if (h != NULL)
	    {
	      h->magic = PRIVATE_MALLOC_HEADER_MAGIC;
	      h->alloc_type = PRIVATE_ALLOC_TYPE_LEA;
	      return private_hl2user_ptr (h);
	    }
	  else
	    {
	      return NULL;
	    }
	}
      else
	{
	  ptr = malloc (size);
	  if (ptr == NULL)
	    {
	      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE,
		      ER_OUT_OF_VIRTUAL_MEMORY, 1, size);
	    }
	  return ptr;
	}
    }
#endif /* SA_MODE */
}