Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2e1579a

Browse files
committed
Make bootstrap debug messages more readable. Clean up some clutter.
1 parent c51b00a commit 2e1579a

File tree

7 files changed

+132
-157
lines changed

7 files changed

+132
-157
lines changed

src/backend/bootstrap/bootparse.y

Lines changed: 75 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.35 2001/01/24 19:42:51 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.36 2001/05/12 01:48:49 petere Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
1616

17-
#include <time.h>
18-
1917
#include "postgres.h"
2018

19+
#include <time.h>
20+
#include <unistd.h>
2121

2222
#include "access/attnum.h"
2323
#include "access/htup.h"
@@ -50,17 +50,31 @@
5050
#include "utils/nabstime.h"
5151
#include "utils/rel.h"
5252

53-
#define DO_START { \
54-
StartTransactionCommand();\
55-
}
5653

57-
#define DO_END { \
58-
CommitTransactionCommand();\
59-
if (!Quiet) { EMITPROMPT; }\
60-
fflush(stdout); \
61-
}
54+
static void
55+
do_start()
56+
{
57+
StartTransactionCommand();
58+
if (DebugMode)
59+
elog(DEBUG, "start transaction");
60+
}
61+
6262

63-
int num_tuples_read = 0;
63+
static void
64+
do_end()
65+
{
66+
CommitTransactionCommand();
67+
if (DebugMode)
68+
elog(DEBUG, "commit transaction");
69+
if (isatty(0))
70+
{
71+
printf("bootstrap> ");
72+
fflush(stdout);
73+
}
74+
}
75+
76+
77+
int num_columns_read = 0;
6478
static Oid objectid;
6579

6680
%}
@@ -71,12 +85,14 @@ static Oid objectid;
7185
IndexElem *ielem;
7286
char *str;
7387
int ival;
88+
Oid oidval;
7489
}
7590

7691
%type <list> boot_index_params
7792
%type <ielem> boot_index_param
7893
%type <ival> boot_const boot_ident
79-
%type <ival> optbootstrap optoideq boot_tuple boot_tuplelist
94+
%type <ival> optbootstrap boot_tuple boot_tuplelist
95+
%type <oidval> optoideq
8096

8197
%token <ival> CONST ID
8298
%token OPEN XCLOSE XCREATE INSERT_TUPLE
@@ -114,42 +130,49 @@ Boot_Query :
114130
Boot_OpenStmt:
115131
OPEN boot_ident
116132
{
117-
DO_START;
133+
do_start();
118134
boot_openrel(LexIDStr($2));
119-
DO_END;
135+
do_end();
120136
}
121137
;
122138

123139
Boot_CloseStmt:
124140
XCLOSE boot_ident %prec low
125141
{
126-
DO_START;
142+
do_start();
127143
closerel(LexIDStr($2));
128-
DO_END;
144+
do_end();
129145
}
130146
| XCLOSE %prec high
131147
{
132-
DO_START;
148+
do_start();
133149
closerel(NULL);
134-
DO_END;
150+
do_end();
135151
}
136152
;
137153

138154
Boot_CreateStmt:
139155
XCREATE optbootstrap boot_ident LPAREN
140156
{
141-
DO_START;
142-
numattr=(int)0;
157+
do_start();
158+
numattr = 0;
159+
if (DebugMode)
160+
{
161+
if ($2)
162+
elog(DEBUG, "creating bootstrap relation %s...",
163+
LexIDStr($3));
164+
else
165+
elog(DEBUG, "creating relation %s...",
166+
LexIDStr($3));
167+
}
143168
}
144169
boot_typelist
145170
{
146-
if (!Quiet)
147-
putchar('\n');
148-
DO_END;
171+
do_end();
149172
}
150173
RPAREN
151174
{
152-
DO_START;
175+
do_start();
153176

154177
if ($2)
155178
{
@@ -158,17 +181,15 @@ Boot_CreateStmt:
158181

159182
if (reldesc)
160183
{
161-
puts("create bootstrap: Warning, open relation");
162-
puts("exists, closing first");
184+
elog(DEBUG, "create bootstrap: warning, open relation exists, closing first");
163185
closerel(NULL);
164186
}
165-
if (DebugMode)
166-
puts("creating bootstrap relation");
187+
167188
tupdesc = CreateTupleDesc(numattr,attrtypes);
168189
reldesc = heap_create(LexIDStr($3), tupdesc,
169190
false, true, true);
170191
if (DebugMode)
171-
puts("bootstrap relation created ok");
192+
elog(DEBUG, "bootstrap relation created");
172193
}
173194
else
174195
{
@@ -181,70 +202,65 @@ Boot_CreateStmt:
181202
RELKIND_RELATION,
182203
false,
183204
true);
184-
if (!Quiet)
185-
printf("CREATED relation %s with OID %u\n",
186-
LexIDStr($3), id);
205+
if (DebugMode)
206+
elog(DEBUG, "relation created with oid %u", id);
187207
}
188-
DO_END;
189-
if (DebugMode)
190-
puts("Commit End");
208+
do_end();
191209
}
192210
;
193211

194212
Boot_InsertStmt:
195213
INSERT_TUPLE optoideq
196214
{
197-
DO_START;
215+
do_start();
198216
if (DebugMode)
199-
printf("tuple %d<", $2);
200-
num_tuples_read = 0;
217+
{
218+
if ($2)
219+
elog(DEBUG, "inserting row with oid %u...", $2);
220+
else
221+
elog(DEBUG, "inserting row...");
222+
}
223+
num_columns_read = 0;
201224
}
202225
LPAREN boot_tuplelist RPAREN
203226
{
204-
if (num_tuples_read != numattr)
205-
elog(ERROR,"incorrect number of values for tuple");
227+
if (num_columns_read != numattr)
228+
elog(ERROR, "incorrect number of columns in row (expected %d, got %d)",
229+
numattr, num_columns_read);
206230
if (reldesc == (Relation)NULL)
207231
{
208-
elog(ERROR,"must OPEN RELATION before INSERT\n");
232+
elog(ERROR, "relation not open");
209233
err_out();
210234
}
211-
if (DebugMode)
212-
puts("Insert Begin");
213235
objectid = $2;
214236
InsertOneTuple(objectid);
215-
if (DebugMode)
216-
puts("Insert End");
217-
if (!Quiet)
218-
putchar('\n');
219-
DO_END;
220-
if (DebugMode)
221-
puts("Transaction End");
237+
do_end();
222238
}
223239
;
224240

225241
Boot_DeclareIndexStmt:
226242
XDECLARE INDEX boot_ident ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
227243
{
228-
DO_START;
244+
do_start();
229245

230246
DefineIndex(LexIDStr($5),
231247
LexIDStr($3),
232248
LexIDStr($7),
233249
$9, NIL, 0, 0, 0, NIL);
234-
DO_END;
250+
do_end();
235251
}
236252
;
237253

238254
Boot_DeclareUniqueIndexStmt:
239255
XDECLARE UNIQUE INDEX boot_ident ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
240256
{
241-
DO_START;
257+
do_start();
242258

243259
DefineIndex(LexIDStr($6),
244260
LexIDStr($4),
245261
LexIDStr($8),
246262
$10, NIL, 1, 0, 0, NIL);
247-
DO_END;
263+
do_end();
248264
}
249265
;
250266

@@ -280,10 +296,8 @@ boot_type_thing:
280296
boot_ident EQUALS boot_ident
281297
{
282298
if(++numattr > MAXATTR)
283-
elog(FATAL,"Too many attributes\n");
299+
elog(FATAL, "too many columns");
284300
DefineAttr(LexIDStr($1),LexIDStr($3),numattr-1);
285-
if (DebugMode)
286-
printf("\n");
287301
}
288302
;
289303

@@ -299,10 +313,10 @@ boot_tuplelist:
299313
;
300314

301315
boot_tuple:
302-
boot_ident {InsertOneValue(objectid, LexIDStr($1), num_tuples_read++); }
303-
| boot_const {InsertOneValue(objectid, LexIDStr($1), num_tuples_read++); }
316+
boot_ident {InsertOneValue(objectid, LexIDStr($1), num_columns_read++); }
317+
| boot_const {InsertOneValue(objectid, LexIDStr($1), num_columns_read++); }
304318
| NULLVAL
305-
{ InsertOneNull(num_tuples_read++); }
319+
{ InsertOneNull(num_columns_read++); }
306320
;
307321

308322
boot_const :

src/backend/bootstrap/bootscanner.l

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootscanner.l,v 1.19 2001/01/24 19:42:51 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootscanner.l,v 1.20 2001/05/12 01:48:49 petere Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
16-
#include <time.h>
17-
1816
#include "postgres.h"
1917

18+
#include <time.h>
19+
2020
#include "access/attnum.h"
2121
#include "access/htup.h"
2222
#include "access/itup.h"
@@ -122,7 +122,7 @@ insert { return(INSERT_TUPLE); }
122122
}
123123

124124
. {
125-
printf("syntax error %d : -> %s\n", yyline, yytext);
125+
elog(ERROR, "syntax error at line %d: unexpected character %s", yyline, yytext);
126126
}
127127

128128

@@ -138,5 +138,5 @@ yywrap(void)
138138
void
139139
yyerror(const char *str)
140140
{
141-
fprintf(stderr,"\tsyntax error %d : %s",yyline, str);
141+
elog(ERROR, "syntax error at line %d: unexpected token %s", yyline, str);
142142
}

0 commit comments

Comments
 (0)