Subject Re: [ib-support] Serialization?
Author Raul Chirea
Hi Matteo,

From: "Matteo Giacomazzi" <matteo.giacomazzi@...>

> Due to netiquette policy, I want that if one thread is downloading a
> document from a host, no other thread should download documents from
> the same host.

How about this scheme:

Create a table, let's say, ACTIVE_HOSTS:

create table ACTIVE_HOSTS (
host_ip varchar(16), /* or some other thing to identify a host */
primary key (host_ip)

and the first thing a download thread does is to start a transaction, let's
call it "TRANS1", and tries to insert a the host_ip in ACTIVE_HOSTS table
using "TRANS1". This insert will fail if another thread is working on the
same host (you'll see later why). Obvious, if the insert fails thread stops
or waits, if not it starts another transaction, let's call it "TRANS2", do
the work using "TRANS2" and, finally, commits "TRANS2" and ROLLBACK !!! the

The ideea is that the insert into ACTIVE_HOSTS fails if another thread
inserted that host before even it didn't commited. The "TRANS1" must be kept
active untill the thread is done with that host and after that (this is the
key part) it rollsback "TRANS1" so the inserted row will disapear making
possible for another thread to start download from that host.

Another ideea is to start "TRANS1" with "isc_tpb_wait" parameter so an
insert in ACTIVE_HOSTS will wait if/untill another thread is done (rollsback
it's "TRANS1").

If you like it, try it ! I'm not very sure this will work (I didn't test
it), but is very probable !