Ejemplo n.º 1
0
/*
 * gtm_get_transactioninfo_size
 * Get a serialized size of GTM_TransactionInfo structure
 *
 * Original gti_gid serialization was just "null-terminated string".
 * This should be prefixed with the length of the string.
 */
size_t
gtm_get_transactioninfo_size(GTM_TransactionInfo *data)
{
	size_t len = 0;

	if (data == NULL)
		return len;

	len += sizeof(GTM_TransactionHandle);		/* gti_handle */
	len += sizeof(uint32);			/* gti_client_id */
	len += sizeof(bool);				/* gti_in_use */
	len += sizeof(GlobalTransactionId);		/* gti_gxid */
	len += sizeof(GTM_TransactionStates);		/* gti_state */
	len += sizeof(GlobalTransactionId);		/* gti_xmin */
	len += sizeof(GTM_IsolationLevel);		/* gti_isolevel */
	len += sizeof(bool);				/* gti_readonly */
	len += sizeof(GTMProxy_ConnID);			/* gti_proxy_client_id */
	len += sizeof(uint32);				/* gti_nodestring length */
	if (data->nodestring != NULL)
		len += strlen(data->nodestring);

	len += sizeof(uint32);
	if (data->gti_gid != NULL)
		len += strlen(data->gti_gid);		/* gti_gid */

	len += gtm_get_snapshotdata_size(&(data->gti_current_snapshot));
	/* gti_current_snapshot */
	len += sizeof(bool);				/* gti_snapshot_set */
	/* NOTE: nothing to be done for gti_lock */
	len += sizeof(bool);				/* gti_vacuum */

	return len;
}
Ejemplo n.º 2
0
/*
 * gtm_serialize_snapshotdata
 * Serialize a GTM_SnapshotData structure
 */
size_t
gtm_serialize_snapshotdata(GTM_SnapshotData *data, char *buf, size_t buflen)
{
	int len = 0;

	memset(buf, 0, buflen);

	/* size check */
	if (gtm_get_snapshotdata_size(data) > buflen)
	  return 0;

	/* GTM_SnapshotData.sn_xmin */
	memcpy(buf + len, &(data->sn_xmin), sizeof(GlobalTransactionId));
	len += sizeof(GlobalTransactionId);

	/* GTM_SnapshotData.sn_xmax */
	memcpy(buf + len, &(data->sn_xmax), sizeof(GlobalTransactionId));
	len += sizeof(GlobalTransactionId);

	/* GTM_SnapshotData.sn_recent_global_xmin */
	memcpy(buf + len, &(data->sn_recent_global_xmin), sizeof(GlobalTransactionId));
	len += sizeof(GlobalTransactionId);

	/* GTM_SnapshotData.sn_xcnt */
	memcpy(buf + len, &(data->sn_xcnt), sizeof(uint32));
	len += sizeof(uint32);

	/* GTM_SnapshotData.sn_xip */
#if 0
	/*
	 * This block of code seems to be wrong.  data->sn_xip is an array of GlobalTransacionIDs
	 * and the number of elements are indicated by sn_xcnt.
	 */
	memcpy(buf + len, &(data->sn_xip), sizeof(GlobalTransactionId));
	len += sizeof(GlobalTransactionId);
#else
	if(data->sn_xcnt > 0)
	{
		memcpy(buf + len, data->sn_xip, sizeof(GlobalTransactionId) * data->sn_xcnt);
		len += sizeof(GlobalTransactionId) * data->sn_xcnt;
	}
#endif

	return len;
}
Ejemplo n.º 3
0
/* -----------------------------------------------------
 * Serialize a GTM_TransactionInfo structure
 * -----------------------------------------------------
 */
size_t
gtm_serialize_transactioninfo(GTM_TransactionInfo *data, char *buf, size_t buflen)
{
	int len = 0;
	char *buf2;
	int i;
	int namelen;

	/* size check */
	if (gtm_get_transactioninfo_size(data) > buflen)
	  return 0;

	memset(buf, 0, buflen);

	/* GTM_TransactionInfo.gti_handle */
	memcpy(buf + len, &(data->gti_handle), sizeof(GTM_TransactionHandle));
	len += sizeof(GTM_TransactionHandle);

	/* GTM_TransactionInfo.gti_client_id */
	memcpy(buf + len, &(data->gti_client_id), sizeof(uint32));
	len += sizeof(uint32);

	/* GTM_TransactionInfo.gti_in_use */
	memcpy(buf + len, &(data->gti_in_use), sizeof(bool));
	len += sizeof(bool);

	/* GTM_TransactionInfo.gti_gxid */
	memcpy(buf + len, &(data->gti_gxid), sizeof(GlobalTransactionId));
	len += sizeof(GlobalTransactionId);

	/* GTM_TransactionInfo.gti_state */
	memcpy(buf + len, &(data->gti_state), sizeof(GTM_TransactionStates));
	len += sizeof(GTM_TransactionStates);

	/* GTM_TransactionInfo.gti_coordname */
	if (data->gti_coordname != NULL)
	{
		namelen = (uint32)strlen(data->gti_coordname);
		memcpy(buf + len, &namelen, sizeof(uint32));
		len += sizeof(uint32);
		memcpy(buf + len, data->gti_coordname, namelen);
		len += namelen;
	}
	else
	{
		namelen = 0;
		memcpy(buf + len, &namelen, sizeof(uint32));
		len += sizeof(uint32);
	}

	/* GTM_TransactionInfo.gti_xmin */
	memcpy(buf + len, &(data->gti_xmin), sizeof(GlobalTransactionId));
	len += sizeof(GlobalTransactionId);

	/* GTM_TransactionInfo.gti_isolevel */
	memcpy(buf + len, &(data->gti_isolevel), sizeof(GTM_IsolationLevel));
	len += sizeof(GTM_IsolationLevel);

	/* GTM_TransactionInfo.gti_readonly */
	memcpy(buf + len, &(data->gti_readonly), sizeof(bool));
	len += sizeof(bool);

	/* GTM_TransactionInfo.gti_backend_id */
	memcpy(buf + len, &(data->gti_backend_id), sizeof(GTMProxy_ConnID));
	len += sizeof(GTMProxy_ConnID);

	/* GTM_TransactionInfo.nodestring */
	if (data->nodestring != NULL)
	{
		uint32 gidlen;

		gidlen = (uint32)strlen(data->nodestring);
		memcpy(buf + len, &gidlen, sizeof(uint32));
		len += sizeof(uint32);
		memcpy(buf + len, data->nodestring, gidlen);
		len += gidlen;
	}
	else
	{
		uint32 gidlen = 0;

		memcpy(buf + len, &gidlen, sizeof(uint32));
		len += sizeof(uint32);
	}

	/* GTM_TransactionInfo.gti_gid */
	if (data->gti_gid != NULL)
	{
		uint32 gidlen;

		gidlen = (uint32)strlen(data->gti_gid);
		memcpy(buf + len, &gidlen, sizeof(uint32));
		len += sizeof(uint32);
		memcpy(buf + len, data->gti_gid, gidlen);
		len += gidlen;
	}
	else
	{
		uint32 gidlen = 0;

		memcpy(buf + len, &gidlen, sizeof(uint32));
		len += sizeof(uint32);
	}

	/* GTM_TransactionInfo.gti_current_snapshot */
	buf2 = malloc(gtm_get_snapshotdata_size(&(data->gti_current_snapshot)));
	i = gtm_serialize_snapshotdata(&(data->gti_current_snapshot),
									buf2,
									gtm_get_snapshotdata_size(&(data->gti_current_snapshot)));
	memcpy(buf + len, buf2, i);
	free(buf2);
	len += i;

	/* GTM_TransactionInfo.gti_snapshot_set */
	memcpy(buf + len, &(data->gti_snapshot_set), sizeof(bool));
	len += sizeof(bool);

	/* GTM_TransactionInfo.gti_lock would not be serialized. */

	/* GTM_TransactionInfo.gti_vacuum */
	memcpy(buf + len, &(data->gti_vacuum), sizeof(bool));
	len += sizeof(bool);

	return len;
}