Prevent tv_sec from becoming negative in connection timeout code.
authorBruce Momjian <[email protected]>
Fri, 11 Oct 2002 04:12:14 +0000 (04:12 +0000)
committerBruce Momjian <[email protected]>
Fri, 11 Oct 2002 04:12:14 +0000 (04:12 +0000)
doc/src/FAQ/FAQ.html
src/backend/nodes/nodes.c
src/backend/utils/mmgr/mcxt.c
src/include/nodes/nodes.h
src/include/utils/palloc.h
src/interfaces/libpq/fe-connect.c

index 54587662260127d91c55db5def960a1169b935d6..a78c41678968a1f439265087895f2053a18d470a 100644 (file)
     from a function?<BR>
      <A href="#4.26">4.26</A>) Why can't I reliably create/drop
     temporary tables in PL/PgSQL functions?<BR>
+     <A href="#4.27">4.27</A>) What replication options are available?<BR>
      
 
     <H2 align="center">Extending PostgreSQL</H2>
@@ -1346,12 +1347,14 @@ BYTEA           bytea           variable-length byte array (null-byte safe)
     <H4><A name="4.24">4.24</A>) How do I perform queries using
     multiple databases?</H4>
 
-    <P>There is no way to query any database except the current one.
+    <P>There is no way to query a database other than the current one.
     Because PostgreSQL loads database-specific system catalogs, it is
     uncertain how a cross-database query should even behave.</P>
 
-    <P>Of course, a client can make simultaneous connections to
-    different databases and merge the information that way.</P>
+    <P><I>/contrib/dblink</I> allows cross-database queries using
+    function calls. Of course, a client can make simultaneous
+    connections to different databases and merge the results on the
+    client side.</P>
 
     <H4><A name="4.25">4.25</A>) How do I return multiple rows or
     columns from a function?</H4>
@@ -1364,13 +1367,19 @@ BYTEA           bytea           variable-length byte array (null-byte safe)
 
     <H4><A name="4.26">4.26</A>) Why can't I reliably create/drop
     temporary tables in PL/PgSQL functions?</H4>
-    PL/PgSQL caches function contents, and an unfortunate side effect
+    <P>PL/PgSQL caches function contents, and an unfortunate side effect
     is that if a PL/PgSQL function accesses a temporary table, and that
     table is later dropped and recreated, and the function called
     again, the function will fail because the cached function contents
     still point to the old temporary table. The solution is to use
     <SMALL>EXECUTE</SMALL> for temporary table access in PL/PgSQL. This
-    will cause the query to be reparsed every time. 
+    will cause the query to be reparsed every time.</P>
+
+    <H4><A name="4.27">4.27</A>) What replication options are available?
+    </H4>
+    <P>There are several master/slave replication solutions available.
+    These allow only one server to make database changes and the slave 
+    merely allow database reading.
 
     <HR>
 
index 1737ccce25212e7f9d922f24ba2e47b78aa2218a..d7d5954a5998f5d98cb8412b6210f36784fe9860 100644 (file)
  *       macro makeNode. eg. to create a Resdom node, use makeNode(Resdom)
  *
  */
-Node *
-newNode(Size size, NodeTag tag)
-{
-       Node       *newNode;
+Node *newNodeMacroHolder;
 
-       Assert(size >= sizeof(Node));           /* need the tag, at least */
-
-       newNode = (Node *) palloc(size);
-       MemSet((char *) newNode, 0, size);
-       newNode->type = tag;
-       return newNode;
-}
index 48b6e8163b9f1cf875324b8384029c7e3c80ad0b..bdf5a1ce4b88e560bcedcccd8ccf2cc012e0ba0f 100644 (file)
@@ -452,6 +452,29 @@ MemoryContextAlloc(MemoryContext context, Size size)
        return (*context->methods->alloc) (context, size);
 }
 
+/*
+ * MemoryContextAllocZero
+ *             Like MemoryContextAlloc, but clears allocated memory
+ *
+ *     We could just call MemoryContextAlloc then clear the memory, but this
+ *     function is called too many times, so we have a separate version.
+ */
+void *
+MemoryContextAllocZero(MemoryContext context, Size size)
+{
+       void *ret;
+
+       AssertArg(MemoryContextIsValid(context));
+
+       if (!AllocSizeIsValid(size))
+               elog(ERROR, "MemoryContextAllocZero: invalid request size %lu",
+                        (unsigned long) size);
+
+       ret = (*context->methods->alloc) (context, size);
+       MemSet(ret, 0, size);
+       return ret;
+}
+
 /*
  * pfree
  *             Release an allocated chunk.
index 54963c64787c41456583dfb9c784e0aa748d15d0..808cfaefc455f632fa942836217c7d08a8694414 100644 (file)
@@ -261,6 +261,24 @@ typedef struct Node
 
 #define nodeTag(nodeptr)               (((Node*)(nodeptr))->type)
 
+/*
+ *     There is no way to dereference the palloc'ed pointer to assign the
+ *     tag, and return the pointer itself, so we need a holder variable.
+ *     Fortunately, this function isn't recursive so we just define
+ *     a global variable for this purpose.
+ */
+extern Node *newNodeMacroHolder;
+
+#define newNode(size, tag) \
+( \
+       AssertMacro((size) >= sizeof(Node)),            /* need the tag, at least */ \
+\
+       newNodeMacroHolder = (Node *) palloc0(size), \
+       newNodeMacroHolder->type = (tag), \
+       newNodeMacroHolder \
+)
+
+
 #define makeNode(_type_)               ((_type_ *) newNode(sizeof(_type_),T_##_type_))
 #define NodeSetTag(nodeptr,t)  (((Node*)(nodeptr))->type = (t))
 
@@ -282,11 +300,6 @@ typedef struct Node
  * ----------------------------------------------------------------
  */
 
-/*
- * nodes/nodes.c
- */
-extern Node *newNode(Size size, NodeTag tag);
-
 /*
  * nodes/{outfuncs.c,print.c}
  */
index 11fc74298dd27d0827c22e381837f30fe7734741..6d2bbc4c47ffe2404569093d8dbb51dedb523fce 100644 (file)
@@ -46,9 +46,12 @@ extern DLLIMPORT MemoryContext CurrentMemoryContext;
  * Fundamental memory-allocation operations (more are in utils/memutils.h)
  */
 extern void *MemoryContextAlloc(MemoryContext context, Size size);
+extern void *MemoryContextAllocZero(MemoryContext context, Size size);
 
 #define palloc(sz)     MemoryContextAlloc(CurrentMemoryContext, (sz))
 
+#define palloc0(sz)    MemoryContextAllocZero(CurrentMemoryContext, (sz))
+
 extern void pfree(void *pointer);
 
 extern void *repalloc(void *pointer, Size size);
index 7b38eb10d1e84248f9c83e8087b38ea74fd4590b..3b888abb0d9340d6ea11e499ceaca9fdd0a156b5 100644 (file)
@@ -1131,7 +1131,10 @@ connectDBComplete(PGconn *conn)
                                return 0;
                        }
 
-                       remains.tv_sec = finish_time - current_time;
+                       if (finish_time > current_time)
+                               remains.tv_sec = finish_time - current_time;
+                       else
+                               remains.tv_sec = 0;
                        remains.tv_usec = 0;
                }
        }