Ejemplo n.º 1
0
/*
 * boot_compact_stop () - stop database compaction
 *   return: error_code
 */
int
boot_compact_stop (THREAD_ENTRY * thread_p)
{
  int current_tran_index = -1;

  if (csect_enter (thread_p, CSECT_COMPACTDB_ONE_INSTANCE, INF_WAIT) !=
      NO_ERROR)
    {
      return ER_FAILED;
    }

  current_tran_index = LOG_FIND_THREAD_TRAN_INDEX (thread_p);
  if (current_tran_index != last_tran_index && compact_started == true)
    {
      csect_exit (CSECT_COMPACTDB_ONE_INSTANCE);
      return ER_FAILED;
    }

  last_tran_index = -1;
  compact_started = false;

  csect_exit (CSECT_COMPACTDB_ONE_INSTANCE);

  return NO_ERROR;
}
Ejemplo n.º 2
0
/*
 * mvcc_is_active_id - check whether given mvccid is active
 *
 * return: bool
 *
 *   thread_p(in): thread entry
 *   id(in): MVCC id
 *
 * Note: Check whether an active transaction is active by searching transactions
 *  status into current history position. The data from current history position
 *  is atomically checked (See logtb_get_mvcc_snapshot_data comments).
 */
STATIC_INLINE bool
mvcc_is_active_id (THREAD_ENTRY * thread_p, MVCCID mvccid)
{
  LOG_TDES *tdes = LOG_FIND_TDES (LOG_FIND_THREAD_TRAN_INDEX (thread_p));
  MVCC_INFO *curr_mvcc_info = NULL, *elem = NULL;
  MVCCTABLE *mvcc_table = &log_Gl.mvcc_table;
  MVCC_INFO *mvccinfo = NULL;
  int try_count = 0;
  UINT64 *p_area;
  int local_bit_area_length;
  MVCCID position, local_bit_area_start_mvccid;
  bool is_active;
  unsigned int i;
  MVCC_TRANS_STATUS *trans_status;
  int index;
  unsigned int trans_status_version;

  assert (tdes != NULL && mvccid != MVCCID_NULL);

  curr_mvcc_info = &tdes->mvccinfo;
  if (MVCC_ID_PRECEDES (mvccid, curr_mvcc_info->recent_snapshot_lowest_active_mvccid))
    {
      return false;
    }

  if (logtb_is_current_mvccid (thread_p, mvccid))
    {
      return true;
    }

#if defined(HAVE_ATOMIC_BUILTINS)
start_check_active:
  index = ATOMIC_INC_32 (&mvcc_table->trans_status_history_position, 0);
  trans_status = mvcc_table->trans_status_history + index;
  trans_status_version = ATOMIC_INC_32 (&trans_status->version, 0);

  local_bit_area_start_mvccid = ATOMIC_INC_64 (&trans_status->bit_area_start_mvccid, 0LL);
  local_bit_area_length = ATOMIC_INC_32 (&trans_status->bit_area_length, 0);

#else
  (void) pthread_mutex_lock (&mvcc_table->active_trans_mutex);
  local_bit_area_length = trans_status->bit_area_length;
  if (local_bit_area_length == 0)
    {
      return false;
    }
  local_bit_area_start_mvccid = mvcc_table->current_trans_status->bit_area_start_mvccid;
#endif

  /* no one can change active transactions while I'm in CS */
  if (MVCC_ID_PRECEDES (mvccid, local_bit_area_start_mvccid))
    {
      is_active = false;
      /* check long time transactions */
      if (trans_status->long_tran_mvccids_length > 0 && trans_status->long_tran_mvccids != NULL)
	{
	  /* called rarely - has long transactions */
	  for (i = 0; i < trans_status->long_tran_mvccids_length; i++)
	    {
	      if (trans_status->long_tran_mvccids[i] == mvccid)
		{
		  break;
		}
	    }
	  if (i < trans_status->long_tran_mvccids_length)
	    {
	      /* MVCCID of long transaction found */
	      is_active = true;
	    }
	}
    }
  else if (local_bit_area_length == 0)
    {
      /* mvccid > highest completed MVCCID */
      is_active = true;
    }
  else
    {
      is_active = true;
      position = mvccid - local_bit_area_start_mvccid;
      if ((int) position < local_bit_area_length)
	{
	  p_area = MVCC_GET_BITAREA_ELEMENT_PTR (trans_status->bit_area, position);
	  if (((*p_area) & MVCC_BITAREA_MASK (position)) != 0)
	    {
	      /* committed transaction found */
	      is_active = false;
	    }
	}
    }

#if defined(HAVE_ATOMIC_BUILTINS)
  if (trans_status_version != ATOMIC_INC_32 (&trans_status->version, 0))
    {
      /* The transaction status version overwritten, need to read again */
      goto start_check_active;
    }
#else
  (void) pthread_mutex_unlock (&mvcc_table->active_trans_mutex);
#endif

  return is_active;
}