On Tue, May 19, 2009 at 11:41 AM, Mark Martinec <mark.martinec+ama...@ijs.si> wrote: > Murilo, > >> I'd like to know how mail IDs are created by amavis. I mean I'd like >> to have two 2 mysql servers replicating as master-master, so the field >> msgs.mail_id cannot be duplicated. > > Entropy is being collected from passing mail and other system sources > readily available to amavisd, then a mail_id is generated from this > random source. Next the save_info_preliminary tries to insert > a record into a table 'msgs' with this generated mail_id: > > 'ins_msg' => > 'INSERT INTO msgs (partition_tag, mail_id, secret_id, am_id,'. > ' time_num, time_iso, sid, policy, client_addr, size, host)'. > ' VALUES (?,?,?,?,?,?,?,?,?,?,?)', > > In an unlikely but possible case that the insertion fails, the probable > cause is there was a clash with an existing mail_id, so another random > mail_id is generated and the procedure repeats up to five times, which > ensures that each mail_id in a database is unique within the range of > records currently kept in a database (within the same partition_tag). > > # create unique mail_id and save preliminary info. to SQL (if enabled) > for (my($attempt)=5;;) { # sanity limit on retries > my($secret_id); > ($mail_id,$secret_id) = generate_mail_id(); > $msginfo->secret_id($secret_id); $secret_id = ''; > $msginfo->mail_id($mail_id); # assign a long-term unique id to the msg > if (!$sql_storage) { > last; # no need to store and no way to check for uniqueness > } else { > # attempt to save a message placeholder to SQL, ensuring it is unique > $which_section = 'sql-enter'; > $sql_storage->save_info_preliminary($conn,$msginfo) and last; > if (--$attempt <= 0) { > do_log(-2,"ERROR sql_storage: too many retries ". > "on storing preliminary, info not saved"); > last; > } else { > snmp_count('GenMailIdRetries'); > do_log(2,"sql_storage: retrying preliminary, %d attempts remain", > $attempt); > sleep(int(1+rand(3))); > add_entropy(Time::HiRes::gettimeofday,$$,$attempt); > } > } > };
Thanks for explanation, Mark. I think the probability on generating duplicated msgs.mail_id between the 2 mysql servers (master-master) is amost impossible :-) Thanks again. -- Murilo Opsfelder Araújo mopsfel...@gmail.com {murilo,pan...@bsd.com.br Don't learn to hack. Hack to learn. BSD will never die. "Tempo difícil esse em que estamos, em que é mais fácil quebrar um átomo do que um preconceito." - Albert Einstein ------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects _______________________________________________ AMaViS-user mailing list AMaViS-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/amavis-user AMaViS-FAQ:http://www.amavis.org/amavis-faq.php3 AMaViS-HowTos:http://www.amavis.org/howto/