Subject: randomized list of MASTER_SITEs (patch)
To: None <tech-pkg@netbsd.org>
From: Mike M. Volokhov <mishka@netbsd.org>
List: tech-pkg
Date: 09/14/2006 18:07:35
--17pEHd4RhPHOinZp
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hello!

As you may note, static list of package master sites accomplished with
some known problems. Huge load on top of the list sites from pkgsrc
users, and died sites (also at the top of list) are most annoying.

At this moment you can shuffle master sites with MASTER_SORT and
MASTER_SORT_REGEX. But you may add some extra randomization with 
just implemented MASTER_SORT_RANDOM=yes|no feature. It will randomize
sites just before any other ordering, so if you altready using some
sorting, your sites will be reshuffled in each group of your selection.
To randomize a whole list use MASTER_SORT_RANDOM=yes only.

To see randomization in action, just add ``| tee /tmp/sites'' to
_RAND_SITES_CMD variable.

--
Mishka.


--17pEHd4RhPHOinZp
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="fetch.mk.patch"

Index: fetch.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/fetch/fetch.mk,v
retrieving revision 1.20
diff -u -r1.20 fetch.mk
--- fetch.mk	27 Jul 2006 18:48:03 -0000	1.20
+++ fetch.mk	14 Sep 2006 17:52:21 -0000
@@ -30,23 +30,35 @@
 _BUILD_DEFS+=	_DISTFILES _PATCHFILES
 
 # Set up _ORDERED_SITES to work out the exact list of sites for every file,
-# using the dynamic sites script, or sorting according to the master site
-# list or the patterns in MASTER_SORT or MASTER_SORT_REGEX as appropriate.
+# using the dynamic sites script, or ordering according to the master site
+# list, MASTER_SORT_RANDOM randomization feature, or the patterns in
+# MASTER_SORT or MASTER_SORT_REGEX as appropriate.
 # No actual sorting is done until _ORDERED_SITES is expanded.
 #
+.if defined(MASTER_SORT_RANDOM) && !empty(MASTER_SORT_RANDOM:M[yY][eE][sS])
+_MASTER_RAND_AWK= { srand(systime()); n = split($$0, site); \
+		    for (i = n; i > 0; i--) { \
+			ir = int(rand() * i + 1); \
+			t = site[i]; site[i] = site[ir]; site[ir] = t; \
+			print site[i]; } }
+_RAND_SITES_CMD= | ${AWK} '${_MASTER_RAND_AWK}'
+.endif
+
 .if defined(MASTER_SORT) || defined(MASTER_SORT_REGEX)
 MASTER_SORT?=
 MASTER_SORT_REGEX?=
 MASTER_SORT_REGEX+= ${MASTER_SORT:S/./\\./g:C/.*/:\/\/[^\/]*&\//}
-
 _MASTER_SORT_AWK= BEGIN { RS = " "; ORS = " "; IGNORECASE = 1 ; gl = "${MASTER_SORT_REGEX:S/\\/\\\\/g}"; }
 .  for srt in ${MASTER_SORT_REGEX}
 _MASTER_SORT_AWK+= /${srt:C/\//\\\//g}/ { good["${srt:S/\\/\\\\/g}"] = good["${srt:S/\\/\\\\/g}"] " " $$0 ; next; }
 .  endfor
 _MASTER_SORT_AWK+= { rest = rest " " $$0; } END { n=split(gl, gla); for(i=1;i<=n;i++) { print good[gla[i]]; } print rest; }
+_SORT_SITES_CMD+= | ${AWK} '${_MASTER_SORT_AWK}'
+.endif
 
-_SORT_SITES_CMD= ${ECHO} $$unsorted_sites | ${AWK} '${_MASTER_SORT_AWK}'
-_ORDERED_SITES= ${_MASTER_SITE_OVERRIDE} `${_SORT_SITES_CMD:S/\\/\\\\/g:C/"/\"/g}`
+.if defined(_RAND_SITES_CMD) || defined(_SORT_SITES_CMD)
+_SORT_SITES_FULL_CMD= ${ECHO} $$unsorted_sites ${_RAND_SITES_CMD} ${_SORT_SITES_CMD}
+_ORDERED_SITES= ${_MASTER_SITE_OVERRIDE} `${_SORT_SITES_FULL_CMD:S/\\/\\\\/g:C/"/\"/g}`
 .else
 _ORDERED_SITES= ${_MASTER_SITE_OVERRIDE} $$unsorted_sites
 .endif

--17pEHd4RhPHOinZp--