View | Details | Raw Unified
Collapse All | Expand All

(-)a/src/slonik/slonik.c (-15 / +66 lines)
 Lines 50-56   extern int STMTS[MAXSTATEMENTS]; Link Here 
50
SlonikScript *parser_script = NULL;
50
SlonikScript *parser_script = NULL;
51
int			parser_errors = 0;
51
int			parser_errors = 0;
52
int			current_try_level;
52
int			current_try_level;
53
53
int			block_stmt_no=0;
54
int last_event_node=-1;
54
int last_event_node=-1;
55
int auto_wait_disabled=0;
55
int auto_wait_disabled=0;
56
56
 Lines 1179-1188   script_exec_stmts(SlonikScript * script, SlonikStmt * hdr) Link Here 
1179
			break;
1179
			break;
1180
	}	
1180
	}	
1181
	free(events);
1181
	free(events);
1182
	
1182
	block_stmt_no=0;
1183
	while (hdr && errors == 0)
1183
	while (hdr && errors == 0)
1184
	{
1184
	{
1185
		hdr->script = script;
1185
		hdr->script = script;
1186
		block_stmt_no++;
1186
1187
1187
		switch (hdr->stmt_type)
1188
		switch (hdr->stmt_type)
1188
		{
1189
		{
 Lines 1191-1200   script_exec_stmts(SlonikScript * script, SlonikStmt * hdr) Link Here 
1191
					SlonikStmt_try *stmt =
1192
					SlonikStmt_try *stmt =
1192
					(SlonikStmt_try *) hdr;
1193
					(SlonikStmt_try *) hdr;
1193
					int			rc;
1194
					int			rc;
1195
					int saved_stmt_no;
1194
1196
1195
					current_try_level++;
1197
					current_try_level++;
1198
					saved_stmt_no=block_stmt_no;
1196
					rc = script_exec_stmts(script, stmt->try_block);
1199
					rc = script_exec_stmts(script, stmt->try_block);
1197
					current_try_level--;
1200
					current_try_level--;
1201
					block_stmt_no=saved_stmt_no;
1198
1202
1199
					if (rc < 0)
1203
					if (rc < 0)
1200
					{
1204
					{
 Lines 1240-1245   script_exec_stmts(SlonikScript * script, SlonikStmt * hdr) Link Here 
1240
					printf("%s:%d: %s\n",
1244
					printf("%s:%d: %s\n",
1241
						   stmt->hdr.stmt_filename, stmt->hdr.stmt_lno,
1245
						   stmt->hdr.stmt_filename, stmt->hdr.stmt_lno,
1242
						   stmt->str);
1246
						   stmt->str);
1247
					block_stmt_no--;
1243
				}
1248
				}
1244
				break;
1249
				break;
1245
1250
 Lines 1258-1263   script_exec_stmts(SlonikScript * script, SlonikStmt * hdr) Link Here 
1258
					printf("%s:%d: %s\n",
1263
					printf("%s:%d: %s\n",
1259
					       stmt->hdr.stmt_filename, stmt->hdr.stmt_lno,
1264
					       stmt->hdr.stmt_filename, stmt->hdr.stmt_lno,
1260
					       outstr);
1265
					       outstr);
1266
					block_stmt_no--;
1261
				}
1267
				}
1262
				break;
1268
				break;
1263
1269
 Lines 3613-3622   slonik_merge_set(SlonikStmt_merge_set * stmt) Link Here 
3613
3619
3614
		if(current_try_level > 0)
3620
		if(current_try_level > 0)
3615
		{
3621
		{
3616
			printf("%s:%d Error: a subscription is in progress. "
3622
			if(current_try_level == 1 && block_stmt_no==1)
3617
				   "slonik can not wait for it to finish inside of a "
3623
			{
3618
				   "try block",stmt->hdr.stmt_filename, stmt->hdr.stmt_lno);
3624
				/**
3619
			return -1;
3625
				 * on the first command of the try block we can 
3626
				 * still a abort the txn and restart it later, 
3627
				 * after the wait for has been complete.
3628
				 */			
3629
			}
3630
			else
3631
			{
3632
				printf("%s:%d Error: a subscription is in progress. "
3633
					   "slonik can not wait for it to finish inside of a "
3634
					   "try block",stmt->hdr.stmt_filename, stmt->hdr.stmt_lno);
3635
				return -1;
3636
			}
3620
		}
3637
		}
3621
3638
3622
		if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
3639
		if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
 Lines 5337-5342   static int slonik_submitEvent(SlonikStmt * stmt, Link Here 
5337
							  int suppress_wait_for)
5354
							  int suppress_wait_for)
5338
{
5355
{
5339
	int rc;
5356
	int rc;
5357
	int recreate_txn=0;
5358
5340
	if ( last_event_node >= 0 &&
5359
	if ( last_event_node >= 0 &&
5341
		 last_event_node != adminfo->no_id
5360
		 last_event_node != adminfo->no_id
5342
		&& ! suppress_wait_for )
5361
		&& ! suppress_wait_for )
 Lines 5349-5358   static int slonik_submitEvent(SlonikStmt * stmt, Link Here 
5349
		
5368
		
5350
		if( current_try_level != 0)
5369
		if( current_try_level != 0)
5351
		{
5370
		{
5352
			printf("%s:%d Error: the event origin can not be changed "
5371
			if( current_try_level==1 && block_stmt_no == 1)
5353
				   "inside of a try block",
5372
			{
5354
				   stmt->stmt_filename, stmt->stmt_lno);
5373
				recreate_txn=1;
5355
			return -1;
5374
				db_rollback_xact(stmt,adminfo);
5375
			}
5376
			else 
5377
			{
5378
				printf("%s:%d Error: the event origin can not be changed "
5379
					   "inside of a try block",
5380
					   stmt->stmt_filename, stmt->stmt_lno);
5381
				return -1;
5382
			}
5356
		}
5383
		}
5357
5384
5358
		/**
5385
		/**
 Lines 5365-5370   static int slonik_submitEvent(SlonikStmt * stmt, Link Here 
5365
		wait_event.wait_confirmed=adminfo->no_id;
5392
		wait_event.wait_confirmed=adminfo->no_id;
5366
		wait_event.wait_timeout=0;
5393
		wait_event.wait_timeout=0;
5367
		rc = slonik_wait_event(&wait_event);
5394
		rc = slonik_wait_event(&wait_event);
5395
		if (recreate_txn)
5396
		{
5397
			db_begin_xact(stmt,adminfo,false);
5398
		}
5368
		if(rc < 0) 
5399
		if(rc < 0) 
5369
			return rc;
5400
			return rc;
5370
		
5401
		
 Lines 5491-5497   static int slonik_wait_config_caughtup(SlonikAdmInfo * adminfo1, Link Here 
5491
	int64* behind_nodes=NULL;
5522
	int64* behind_nodes=NULL;
5492
	int idx;
5523
	int idx;
5493
	int cur_array_idx;
5524
	int cur_array_idx;
5494
	
5525
	int recreate_txn=0;
5526
5495
	/**
5527
	/**
5496
	 * an array that stores a node_id, last_event.
5528
	 * an array that stores a node_id, last_event.
5497
	 * or the last event seen for each admin conninfo
5529
	 * or the last event seen for each admin conninfo
 Lines 5505-5513   static int slonik_wait_config_caughtup(SlonikAdmInfo * adminfo1, Link Here 
5505
5537
5506
	if( current_try_level != 0)
5538
	if( current_try_level != 0)
5507
	{
5539
	{
5508
	  printf("%s:%d Error: WAIT operation forbidden inside a try block\n",
5540
	  if( current_try_level==1 && block_stmt_no ==1)
5509
			 stmt->stmt_filename, stmt->stmt_lno);
5541
	  {
5510
	  return -1;
5542
		  /**
5543
		   * The first statement in the try block requires
5544
		   * a wait for.  the code below will rollback the txn.
5545
		   * we set a flag so we know to create a new one 
5546
		   * when we are done.
5547
		   */
5548
		  recreate_txn=1;
5549
	  }
5550
	  else 
5551
	  {
5552
		  printf("%s:%d Error: WAIT operation forbidden inside a try block\n",
5553
				 stmt->stmt_filename, stmt->stmt_lno);
5554
		  return -1;
5555
	  }
5511
	}
5556
	}
5512
5557
5513
	for( curAdmInfo = stmt->script->adminfo_list;
5558
	for( curAdmInfo = stmt->script->adminfo_list;
 Lines 5670-5677   static int slonik_wait_config_caughtup(SlonikAdmInfo * adminfo1, Link Here 
5670
	 if(result != NULL)
5715
	 if(result != NULL)
5671
			 PQclear(result);    
5716
			 PQclear(result);    
5672
	 dstring_terminate(&event_list);
5717
	 dstring_terminate(&event_list);
5673
	 dstring_terminate(&is_caughtup_query);
5718
	 dstring_terminate(&is_caughtup_query);	 
5674
	 free(last_event_array);
5719
	 free(last_event_array);
5720
	 
5721
	 if(recreate_txn)
5722
	 {
5723
		 db_begin_xact(stmt,adminfo1,false);
5724
	 }
5725
5675
	 return 0;
5726
	 return 0;
5676
5727
5677
}
5728
}