]> granicus.if.org Git - postgresql/blobdiff - src/backend/utils/adt/txid.c
Add support for EUI-64 MAC addresses as macaddr8
[postgresql] / src / backend / utils / adt / txid.c
index 31f8033ae4846f8bd0149db8f0b81edb2c1969d9..772d7c72031a1c47e840835add6befb7475e48a0 100644 (file)
@@ -10,7 +10,7 @@
  * via functions such as SubTransGetTopmostTransaction().
  *
  *
- *     Copyright (c) 2003-2015, PostgreSQL Global Development Group
+ *     Copyright (c) 2003-2017, PostgreSQL Global Development Group
  *     Author: Jan Wieck, Afilias USA INC.
  *     64-bit txids: Marko Kreen, Skype Technologies
  *
@@ -34,7 +34,7 @@
 
 
 /* txid will be signed int8 in database, so must limit to 63 bits */
-#define MAX_TXID   ((uint64) INT64_MAX)
+#define MAX_TXID   ((uint64) PG_INT64_MAX)
 
 /* Use unsigned variant internally */
 typedef uint64 txid;
@@ -142,8 +142,10 @@ cmp_txid(const void *aa, const void *bb)
 static void
 sort_snapshot(TxidSnapshot *snap)
 {
-       txid    last = 0;
-       int             nxip, idx1, idx2;
+       txid            last = 0;
+       int                     nxip,
+                               idx1,
+                               idx2;
 
        if (snap->nxip > 1)
        {
@@ -332,8 +334,11 @@ parse_snapshot(const char *str)
        return buf_finalize(buf);
 
 bad_format:
-       elog(ERROR, "invalid input for txid_snapshot: \"%s\"", str_start);
-       return NULL;
+       ereport(ERROR,
+                       (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+                        errmsg("invalid input syntax for type %s: \"%s\"",
+                                       "txid_snapshot", str_start)));
+       return NULL;                            /* keep compiler quiet */
 }
 
 /*
@@ -371,6 +376,27 @@ txid_current(PG_FUNCTION_ARGS)
        PG_RETURN_INT64(val);
 }
 
+/*
+ * Same as txid_current() but doesn't assign a new xid if there isn't one
+ * yet.
+ */
+Datum
+txid_current_if_assigned(PG_FUNCTION_ARGS)
+{
+       txid            val;
+       TxidEpoch       state;
+       TransactionId   topxid = GetTopTransactionIdIfAny();
+
+       if (topxid == InvalidTransactionId)
+               PG_RETURN_NULL();
+
+       load_xid_epoch(&state);
+
+       val = convert_xid(topxid, &state);
+
+       PG_RETURN_INT64(val);
+}
+
 /*
  * txid_current_snapshot() returns txid_snapshot
  *
@@ -524,8 +550,10 @@ txid_snapshot_recv(PG_FUNCTION_ARGS)
        PG_RETURN_POINTER(snap);
 
 bad_format:
-       elog(ERROR, "invalid snapshot data");
-       return (Datum) NULL;
+       ereport(ERROR,
+                       (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
+                        errmsg("invalid external txid_snapshot data")));
+       PG_RETURN_POINTER(NULL);        /* keep compiler quiet */
 }
 
 /*