platform/upstream/rpm.git
11 years agoChange poolHash to use internal collision resolution
Florian Festi [Tue, 18 Sep 2012 08:55:51 +0000 (10:55 +0200)]
Change poolHash to use internal collision resolution

11 years agoEliminate strdup() in doLookupId()
Panu Matilainen [Wed, 19 Sep 2012 10:01:59 +0000 (13:01 +0300)]
Eliminate strdup() in doLookupId()

- Take advantage of the length-aware pool string->id lookup to avoid
  the need to copy and locally modify the canonized dirname. Makes
  the code cleaner and a little bit faster too.
- There are further possibilities in this direction, canonDir()
  could return an id instead of malloced memory but that doesn't
  remove the need for temporary bugg^H^Hffer to clean up the dir.

11 years agoLift directory name canonicalization into a helper function
Panu Matilainen [Wed, 19 Sep 2012 09:50:31 +0000 (12:50 +0300)]
Lift directory name canonicalization into a helper function

- Suddenly it all seems so much clearer...
- Also try to better handle the theoretical realpath() errors: on
  failure the buffer contents are undefined and we shouldn't look
  at them, free the buf and return NULL.

11 years agoAargh, stupid thinko in rpmstrPoolStrlen() last id special case
Panu Matilainen [Wed, 19 Sep 2012 07:42:59 +0000 (10:42 +0300)]
Aargh, stupid thinko in rpmstrPoolStrlen() last id special case

- At the largest id, the end boundary is data, not offset size... doh

11 years agoUnbreak fingerprinting when called twice for the same transaction set
Panu Matilainen [Tue, 18 Sep 2012 16:04:40 +0000 (19:04 +0300)]
Unbreak fingerprinting when called twice for the same transaction set

- Fixes regression (yum updates barf with conflicts) from commit
  3b492620fb35a21d05b975e31130dc071f6fd8e2 which doesn't affect rpm
  itself but breaks some API users like yum that first run a
  test-transaction and if that succeeds, the same transaction is run
  for real. In that case we need to redo the whole fingerprint dance
  from scratch: throw away any former results and redo.
- Blaming Fedora 18 alpha preparations for not noticing this earlier:
  there have been no updates to F16/F17 in almost a week, effectively
  disabling a part of the regular rpm development QA :P

11 years agoOops, refactoring error in commit 327701572ff912413ec9564d29d946b4ab21a9f3
Panu Matilainen [Tue, 18 Sep 2012 07:40:18 +0000 (10:40 +0300)]
Oops, refactoring error in commit 327701572ff912413ec9564d29d946b4ab21a9f3

- sizeof() doesn't work very well for malloced arrays... not that it
  matters a whole lot, this isn't a path that will ever be executed
  afaict.

11 years agoEnsure fingerprint subdirs have heading slashes
Panu Matilainen [Tue, 18 Sep 2012 07:03:13 +0000 (10:03 +0300)]
Ensure fingerprint subdirs have heading slashes

- Similar to commit ad99f4e84a5fea05edca59257b6e00d91d6c8a08 but at the
  other end of the name: not all subdirs will exist in the pool already
  but none of them exists without the heading slash. Saves another handful
  of megs on larger transactions.

11 years agoEnsure directories have trailing slashes in doLookupId()
Panu Matilainen [Tue, 18 Sep 2012 06:39:38 +0000 (09:39 +0300)]
Ensure directories have trailing slashes in doLookupId()

- In the old days, stripping trailing slashes made sense as its useless
  as it is and stripping it saved a bit of memory, but now with the
  directories in the pool things are different: while not all paths
  we'll see here necessarily exist in the pool already, NONE of them
  exists without the trailing slash, so stripping it out wastes gobs
  of memory.  Simplifies the code a bit and saves several megs of memory
  on larger transactions, what's not to like?

11 years agoFurther doLookupId() cleanup
Panu Matilainen [Tue, 18 Sep 2012 04:29:43 +0000 (07:29 +0300)]
Further doLookupId() cleanup

- Refer to dirName when we haven't yet cleaned it up to clarify uses,
  only initialize the const cleaned dir name pointer after we've
  successfully cleaned it up. Rename cleanDirName to cdn to keep it
  sweet and short, and suggest the relation to cdnl and cdnbuf.

11 years agoElimiate one of the umphteen directory variables in doLookupId()
Panu Matilainen [Tue, 18 Sep 2012 03:56:46 +0000 (06:56 +0300)]
Elimiate one of the umphteen directory variables in doLookupId()

- Use dynamically allocated cdnbuf in the non-absolute path case (when
  exactly that occurs is another question) too instead of the on-stack
  dir[], making the two paths a bit more similar.

11 years agoAvoid redundant ds -> id -> string lookups in rpmalAllFileSatisfiesDepend()
Panu Matilainen [Tue, 18 Sep 2012 03:30:59 +0000 (06:30 +0300)]
Avoid redundant ds -> id -> string lookups in rpmalAllFileSatisfiesDepend()

- We need to grab the dependency string in rpmalAllSatisfiesDepend()
  already to see whether its a file dependency or not, just pass that
  to the file deps to avoid redundant work.

11 years agoDont bother with separate notifications on multiple file dep matches
Panu Matilainen [Tue, 18 Sep 2012 03:27:57 +0000 (06:27 +0300)]
Dont bother with separate notifications on multiple file dep matches

11 years agoAvoid the string copy in rpmalAllFileSatisfiesDepend() now that we can
Panu Matilainen [Tue, 18 Sep 2012 03:26:34 +0000 (06:26 +0300)]
Avoid the string copy in rpmalAllFileSatisfiesDepend() now that we can

11 years agoMake pool string->id operations properly length-aware
Panu Matilainen [Tue, 18 Sep 2012 03:01:43 +0000 (06:01 +0300)]
Make pool string->id operations properly length-aware

- Allow looking up and inserting partial key strings, this is useful
  in various cases where previously a local copy was needed for
  \0-terminating the key in the caller.
- Take advantage of rstrlenhash() in rpmstrPoolId(), previously the
  length was only interesting when adding so we wasted a strlen()
  on every call when the string was already in the pool.

11 years agoAdd length aware variant(s) of string hashing
Panu Matilainen [Tue, 18 Sep 2012 01:46:10 +0000 (04:46 +0300)]
Add length aware variant(s) of string hashing

- Being able to hash partial strings is needed for allowing string pool
  to operate on partial strings...

11 years agoEnhanced string hash to permit calculating string length on the same call
Panu Matilainen [Tue, 18 Sep 2012 01:34:38 +0000 (04:34 +0300)]
Enhanced string hash to permit calculating string length on the same call

- String hashing needs to walk the entire string anyhow, might as well
  take advantage of this and have it return the string length to avoid
  having to separately call strlen() in the cases where this matters.
- Move the implementation into rpmstrpool.c for inlining possibilities,
  rstrhash() is now just a wrapper to rstrlenhash(). The generic
  hash implementation could not take advantage of this anyway really.

11 years agoDont assume \0 terminated strings in rpmstrPoolPut()
Panu Matilainen [Tue, 18 Sep 2012 01:15:56 +0000 (04:15 +0300)]
Dont assume \0 terminated strings in rpmstrPoolPut()

- Before this, the slen argument was only good for avoiding an extra
  strlen() but being able to handle shove and lookup partial strings
  without local copy+modify in callers is handy, this is one of
  the prerequisites for that.

11 years agoUse pool id's for hash table key, lookup strings from pool as needed
Panu Matilainen [Mon, 17 Sep 2012 12:52:59 +0000 (15:52 +0300)]
Use pool id's for hash table key, lookup strings from pool as needed

- The pool itself can address its contents by id alone, storing
  pointers to the strings only hurts as reallocation moving the
  data blob requires rehashing the whole thing needlessly.
- We now store just the key id in the hash buckets, and lookup the
  actual string for comparison from the pool. This avoids the
  need to rehash on realloc and saves memory too, and this is one of
  the biggest reasons for wanting a separate hash implementation for
  the string pool. Incidentally, this is how libsolv does it too.
- Individual bucket allocation becomes rather wasteful now: a bucket
  stores a single integer, and a single pointer to the next bucket,
  a pointer  which can be twice the size of the key data it holds.
  Further tuning and cleaning up after the marriage of these two
  datatypes left after the honeymoon is over...

11 years agoMove the string pool struct definition earlier so we can reference it...
Panu Matilainen [Mon, 17 Sep 2012 12:32:36 +0000 (15:32 +0300)]
Move the string pool struct definition earlier so we can reference it...

11 years agoInline poolHashfindEntry() into GetEntry(), nothing else needs it
Panu Matilainen [Mon, 17 Sep 2012 12:18:01 +0000 (15:18 +0300)]
Inline poolHashfindEntry() into GetEntry(), nothing else needs it

11 years agoEliminate key comparison and hash function vectors from poolHash
Panu Matilainen [Mon, 17 Sep 2012 12:01:46 +0000 (15:01 +0300)]
Eliminate key comparison and hash function vectors from poolHash

- As the pool is hardwired to single hash type, these dont make
  any sense here and the extra indirection will only hurt performance.

11 years agoMore poolHash multiple data-value cleanups
Panu Matilainen [Mon, 17 Sep 2012 11:48:21 +0000 (14:48 +0300)]
More poolHash multiple data-value cleanups

- The only data associated with a pool key is a single id, we dont need
  an array for that
- Change poolHash get-entry return the id directly instead of pointer array

11 years agoEliminate redundant data counting from poolHash
Panu Matilainen [Mon, 17 Sep 2012 11:43:43 +0000 (14:43 +0300)]
Eliminate redundant data counting from poolHash

- There's a strict 1:1 relation between keys and data in the string
  pool, this keeping count of data is pointless.

11 years agoEliminate unnecessary key and data free-functionality from poolHash
Panu Matilainen [Mon, 17 Sep 2012 11:30:55 +0000 (14:30 +0300)]
Eliminate unnecessary key and data free-functionality from poolHash

11 years agoPull a private hash-implementation copy to string pool
Panu Matilainen [Mon, 17 Sep 2012 11:20:30 +0000 (14:20 +0300)]
Pull a private hash-implementation copy to string pool

- The string pool is more specialized a data structure to be efficiently
  handled with the generic hash table implementation in rpmhash.[CH]
  and really requires quite a different approach.
- For starters, import a private copy generated roughly with:
      gcc -E -DHASHTYPE=poolHash \
             -DHTKEYTYPE="const char *" -DHTDATATYPE=rpmsid rpmhash.C
  ...and clean it up a bit: eliminate unused functions (except for
  stats which we'll want to keep for debug purposes), make remaining
  functions static and overall tidy up from the mess 'gcc -E' created.
  Lots of redundant fluff here still, to be cleaned up gradually...
- This doesn't change anything at all, but opens up the playground
  for tuning the pool hash implementation in ways the generic version
  could not (at least sanely) be.

11 years agoRename string pool hash type to poolHash
Panu Matilainen [Mon, 17 Sep 2012 10:33:42 +0000 (13:33 +0300)]
Rename string pool hash type to poolHash

- No changes other than a rename for next steps...

11 years agoPermit key imports even if signature checking is disabled (RhBug:856225)
Panu Matilainen [Mon, 17 Sep 2012 07:48:05 +0000 (10:48 +0300)]
Permit key imports even if signature checking is disabled (RhBug:856225)

- Since commit 290fcbbe6b3ca2fb1d5e4a7269a32a94f8a1563a, key imports
  on transaction sets where signature checking is disabled would fail
  due to keyring not getting loaded at all. A regression of sorts,
  in other words. As a minimal fix, temporarily enable sigcheck vsflags
  during keyring loading.

11 years agoLift string pool rehash into a separate helper function
Panu Matilainen [Sat, 15 Sep 2012 10:01:53 +0000 (13:01 +0300)]
Lift string pool rehash into a separate helper function

- This way we have exactly one place for controlling hash (re)creation
  size strategies etc.

11 years agoUse a saner pool hash resize hint
Panu Matilainen [Sat, 15 Sep 2012 09:49:15 +0000 (12:49 +0300)]
Use a saner pool hash resize hint

- The previous size hint would actually cause us to shrink the hash
  bucket allocation, requiring the hash to resize itself immediately
  afterwards. As if the rehashes weren't expensive enough already...

11 years agoBe more selective about legacy retrofits on package read
Panu Matilainen [Sat, 15 Sep 2012 09:14:43 +0000 (12:14 +0300)]
Be more selective about legacy retrofits on package read

- Missing RPMTAG_DIRNAME can mean either a package with uncompressed
  filenames OR a new package with no files, in which case the retrofits
  should not be performed. Also a newer package can be built with
  --nodirtokens, requiring filelist compression but no other retrofits.
- Test for immutable region presence for more accurate v3 package
  detection, if not present do a full retrofit. For others, explicitly
  test for OLDFILENAMES presence and only compress the filelist if needed.e

11 years agoSwitch rpmdb basename finding to use pool id's instead of strings
Panu Matilainen [Fri, 14 Sep 2012 16:55:03 +0000 (19:55 +0300)]
Switch rpmdb basename finding to use pool id's instead of strings

- Ids are both faster to hash/compare and cheaper to store than string
  pointers. Not a huge win but a win anyway...

11 years agoCleanup + optimize doLookupId() a bit
Panu Matilainen [Fri, 14 Sep 2012 15:31:19 +0000 (18:31 +0300)]
Cleanup + optimize doLookupId() a bit

- Eliminate redundant second strlen() on dirName on entry, and avoid
  the first one as well by grabbing the length from pool instead.
- Reorganize the initializations and declarations a bit for clarity.

11 years agoRemove leftover variable from previous commit
Panu Matilainen [Fri, 14 Sep 2012 13:03:07 +0000 (16:03 +0300)]
Remove leftover variable from previous commit

- Should've been in commit 1770fca303c5c5abdb27040649b458b59494823

11 years agoChange fpLookupList() to operate on pool id's only
Panu Matilainen [Fri, 14 Sep 2012 12:03:21 +0000 (15:03 +0300)]
Change fpLookupList() to operate on pool id's only

11 years agoDo the low-level fingerprint lookup based on pool id arguments
Panu Matilainen [Fri, 14 Sep 2012 11:49:04 +0000 (14:49 +0300)]
Do the low-level fingerprint lookup based on pool id arguments

- When at all possible, we'd prefer working on id's instead of
  actual strings, change the lowest-level fingerprint lookup to
  use those, doLookup() is now just a wrapper to handle string ->
  pool id conversion before doing the actual work. This shouldn't
  affect anything at all yet.

11 years agoSwitch fingerprinting to use the global string pool
Panu Matilainen [Fri, 14 Sep 2012 11:21:45 +0000 (14:21 +0300)]
Switch fingerprinting to use the global string pool

- Transaction preparation fingerprinting now shares all the strings from
  rpmfi's etc. Rpmdb basename iterator still needs a private pool
  as there's nowhere to get a pool handle (for now at least).
- We no longer need to (and actually we couldn't) freeze the
  pool before fingerprinting.

11 years agoAllow passing a shared pool for finger print cache
Panu Matilainen [Fri, 14 Sep 2012 11:21:10 +0000 (14:21 +0300)]
Allow passing a shared pool for finger print cache

- Both callers updated to still use a private pool so no practical
  change here.

11 years agoRemove scareMemory remnants from the internal API, fixup callers
Panu Matilainen [Fri, 14 Sep 2012 11:19:32 +0000 (14:19 +0300)]
Remove scareMemory remnants from the internal API, fixup callers

11 years agoSwitch fingerprint subDir to pool ids
Panu Matilainen [Fri, 14 Sep 2012 11:12:08 +0000 (14:12 +0300)]
Switch fingerprint subDir to pool ids

- <gulp> but no anomalies noted by test-suite, valgrind or
  a bit of manual testing. Time will tell...
- Memory is no longer scarce or scary, the strings are simply owned
  by the pool in all circumstances. Eliminate scareMemory foobar
  from the fingerprinting internals.

11 years agoSwitch fingerprint basename to pool ids
Panu Matilainen [Fri, 14 Sep 2012 07:50:53 +0000 (10:50 +0300)]
Switch fingerprint basename to pool ids

- For now we're doing a fair amount of extra work and wasting memory
  as data is in different pools so we need to copy to get the strings
  and ids into our private pool. This will go away later.

11 years agoSwitch fingerprint cache-entry dirnames to pool ids
Panu Matilainen [Fri, 14 Sep 2012 07:24:13 +0000 (10:24 +0300)]
Switch fingerprint cache-entry dirnames to pool ids

- This is fairly straightforward (or supposed to be...) especially
  now that its all hidden behind APIs. Note that we no longer bother
  precalculating the hash as a pool-id's hash is a no-cost operation,
  for strings it was far more expensive.

11 years agoAdd a string pool to fingerprint cache (but not yet used)
Panu Matilainen [Fri, 14 Sep 2012 07:01:54 +0000 (10:01 +0300)]
Add a string pool to fingerprint cache (but not yet used)

11 years agoMake fingerprint struct opaque outside fprint.c
Panu Matilainen [Fri, 14 Sep 2012 06:28:50 +0000 (09:28 +0300)]
Make fingerprint struct opaque outside fprint.c

- rpmfi cannot know anything about the storage, so rpmfiFpxIndex()
  cannot be... change it to rpmfiFps() which only returns the pointer
  we got from fpLookupList()
- Change fpCacheGetByFp() to assume it gets passed an array of fps,
  and take an additional index argument. Return the fingerprint
  pointer on success, NULL on not found to allow further operations
  on the fp without knowing its internals.

11 years agoChange fpLookup() to return malloced memory (on first call)
Panu Matilainen [Fri, 14 Sep 2012 05:41:01 +0000 (08:41 +0300)]
Change fpLookup() to return malloced memory (on first call)

- If the fingerprint pointer passed to it is NULL then allocate space
  for a new fingerprint, otherwise reuse the previous space. This should
  allow optimizing the case where repeatedly calling and directory
  doesn't change inside fpc so callers dont need special-case code
  for this. For now, we dont care about optimizations, other than
  making it possible later.

11 years agoMake fingerprint cache entry opaque, add some kind of API for the needed bits
Panu Matilainen [Fri, 14 Sep 2012 04:45:44 +0000 (07:45 +0300)]
Make fingerprint cache entry opaque, add some kind of API for the needed bits

- Only disk-space calculations need the actual entry contents, add
  getter for dir name and device. We're passing the cache to these
  getters too: its not currently unusedd but will be needed for
  directory name pool id->string translation once we get there...

11 years agoHide away the FP_EQUAL macros
Panu Matilainen [Fri, 14 Sep 2012 04:14:14 +0000 (07:14 +0300)]
Hide away the FP_EQUAL macros

11 years agoChange fpLookupList() to return malloced memory
Panu Matilainen [Thu, 13 Sep 2012 21:21:04 +0000 (00:21 +0300)]
Change fpLookupList() to return malloced memory

- Eliminates one place where knowledge about fingerprint internals
  has been needed, now rpmfi just gets (an supposedly) opaque blob back.

11 years agoAdd internal API for fingerprint lookup-and-compare
Panu Matilainen [Thu, 13 Sep 2012 21:10:45 +0000 (00:10 +0300)]
Add internal API for fingerprint lookup-and-compare

- Replace the direct hackery in rpmdb internals with a little less
  direct hackery...

11 years agoBury the fingerprint hash-types into fprint.c, clean up
Panu Matilainen [Thu, 13 Sep 2012 19:41:41 +0000 (22:41 +0300)]
Bury the fingerprint hash-types into fprint.c, clean up

- fprint.h only needs rpmtypes.h now, remove historical leftovers
- Avoids having to define the hash types multiple times as they're
  now buried out of sight
- fpHashFunction() and fpLookupSubdir() can now be made static, do so...

11 years agoMove the entire fingerprint cache population into fprint.c
Panu Matilainen [Thu, 13 Sep 2012 19:19:40 +0000 (22:19 +0300)]
Move the entire fingerprint cache population into fprint.c

- Rename addFingerprints() to fpCachePopulate() and move into fprint.c.
  This doesn't really belong here as it requires fprint becoming aware
  of transactions and all, but at least these are all controlled API
  accesses unlike where in transaction.c this was messing with somebody
  elses data structures directly.
- Move the by-fingerprint creation to fpCachePopulate() so it gets
  lazily done as needed and copy the original hash-size heuristics
  back here.

11 years agoHide by-fingerprint hash into fingerprint cache, add minimal API bits
Panu Matilainen [Thu, 13 Sep 2012 18:52:38 +0000 (21:52 +0300)]
Hide by-fingerprint hash into fingerprint cache, add minimal API bits

- For now, always create the by-fingerprint hash although rpmdb usage
  doesn't need it. Next steps will fix...
- Add wrapper API for retrieving the records, adjust callers
- No functional changes, at least intended ones... just first steps
  towards eliminating the hash-jungle and forcing a single API
  through which this stuff gets handled

11 years agoMake fingerprint cache opaque outside fprint.c
Panu Matilainen [Thu, 13 Sep 2012 18:13:47 +0000 (21:13 +0300)]
Make fingerprint cache opaque outside fprint.c

- Not that it matters much when everything else is wide open but gotta
  start with something...

11 years agoConvert our dependency checking code to use the new rpmdsMatches()
Panu Matilainen [Thu, 13 Sep 2012 10:12:59 +0000 (13:12 +0300)]
Convert our dependency checking code to use the new rpmdsMatches()

- Instead of adding three more pool-aware versions of the old API's,
  convert the main callers to the newew more flexible API. As a
  "minor side-effect" these now use the transaction string-pool as well,
  so ALL our pre-transaction dependency sets are now using the global
  pool.

11 years agoUnify the three rpmdsFooMatchesDep() functions into one
Panu Matilainen [Thu, 13 Sep 2012 09:46:41 +0000 (12:46 +0300)]
Unify the three rpmdsFooMatchesDep() functions into one

- These all do more or less the same thing, easily handled with a common
  function that takes a couple of more extra parameters. The old variants
  become just wrappers to call the pool-aware rpmdsMatches() with suitable
  arguments.

11 years agoUse transaction string pool for rpmlib() dependencies too
Panu Matilainen [Thu, 13 Sep 2012 08:55:52 +0000 (11:55 +0300)]
Use transaction string pool for rpmlib() dependencies too

- This wasn't possible with the former static rpmlib() dependency set
  as it would've kept the potentially huge global pool referenced
  throughout process lifetime.

11 years agoAdd pool-aware version of rpmdsRpmlib()
Panu Matilainen [Thu, 13 Sep 2012 08:54:54 +0000 (11:54 +0300)]
Add pool-aware version of rpmdsRpmlib()

11 years agoHang rpmlib() dependency set onto transaction set
Panu Matilainen [Thu, 13 Sep 2012 08:45:29 +0000 (11:45 +0300)]
Hang rpmlib() dependency set onto transaction set

- Eliminates the cumbersome static rpmlib ds instance which can never
  be freed, as a member of the transaction set it simply gets cleaned
  out along with other transaction (dependency) data.

11 years agoUse transaction string pool for ensureOlder() dependency sets
Panu Matilainen [Thu, 13 Sep 2012 08:36:27 +0000 (11:36 +0300)]
Use transaction string pool for ensureOlder() dependency sets

11 years agoUse transaction string pool for findPos() dependency sets
Panu Matilainen [Thu, 13 Sep 2012 08:35:57 +0000 (11:35 +0300)]
Use transaction string pool for findPos() dependency sets

11 years agoPut transaction element "self" dependency set into global pool too
Panu Matilainen [Thu, 13 Sep 2012 08:18:23 +0000 (11:18 +0300)]
Put transaction element "self" dependency set into global pool too

11 years agoAdd pool-aware versions of rpmdsThis() and rpmdsSingle()
Panu Matilainen [Thu, 13 Sep 2012 07:56:42 +0000 (10:56 +0300)]
Add pool-aware versions of rpmdsThis() and rpmdsSingle()

- Pooh ... I mean pool ... bah. The previous  versions become simple
  wrappers to the pool-aware ones, using a private pool always.
  rpmdsCurrent() doesn't need pool-variant as its inherits its pool
  from the parent.

11 years agoSimplify single ds creation
Panu Matilainen [Thu, 13 Sep 2012 07:39:28 +0000 (10:39 +0300)]
Simplify single ds creation

- Eliminate the pre-created pool wtf'ery (what was I thinking?), just
  create a ds with zero id's and fill them up once we have the ds.

11 years agoAdd a string equality check function to string pool API
Panu Matilainen [Thu, 13 Sep 2012 05:48:56 +0000 (08:48 +0300)]
Add a string equality check function to string pool API

- As a special case, two strings (ids) from the same pool can be tested for
  equality in constant time (integer comparison). If the pools differ,
  a regular string comparison is needed.

11 years agoWhoopsie, unbreak checking of installed dependencies
Panu Matilainen [Wed, 12 Sep 2012 17:11:00 +0000 (20:11 +0300)]
Whoopsie, unbreak checking of installed dependencies

- The dependency sets created from installed headers during rpmtsCheck()
  were using a private pool and thus ids not matching with the ones
  in the global pool. Oops. Somehow none of our test-suite cases
  caught this, looks like we'll need more tests... Also the safe-guard
  assert()'s are in all the wrong places for catching this particular
  problem. Doh :)
- There's a chicken-and-egg situation involved: in order to do this,
  the global pool needs to be in unfrozen state during rpmtsCheck(),
  which was not possible before switching rpmal provides (and files)
  to pool ids. Now that it *is* using pool id's, move the freeze-point
  to rpmtsPrepare() as the fingerprinting has similar issues with
  moving strings.

11 years agoOnly rehash the pool on insert if the data area actually moved
Panu Matilainen [Wed, 12 Sep 2012 16:29:28 +0000 (19:29 +0300)]
Only rehash the pool on insert if the data area actually moved

- realloc() might not need to actually move the data, and when it
  doesn't we dont need to do the very expensive rehash either.
  Unsurprisingly makes things a whole lot faster.

11 years agoSwitch rpmal file hash to use pool id's instead of strings
Panu Matilainen [Wed, 12 Sep 2012 16:20:52 +0000 (19:20 +0300)]
Switch rpmal file hash to use pool id's instead of strings

11 years agoSwitch rpmal provide hash to use pool id's instead of strings
Panu Matilainen [Wed, 12 Sep 2012 13:51:12 +0000 (16:51 +0300)]
Switch rpmal provide hash to use pool id's instead of strings

11 years agoAdd a some transition-period asserts to ensure pool-usage sanity
Panu Matilainen [Wed, 12 Sep 2012 13:50:41 +0000 (16:50 +0300)]
Add a some transition-period asserts to ensure pool-usage sanity

11 years agoAllow keeping hash table around on pool freeze, adjust callers
Panu Matilainen [Wed, 12 Sep 2012 13:47:43 +0000 (16:47 +0300)]
Allow keeping hash table around on pool freeze, adjust callers

- Pool id -> string always works with a frozen pool, but in some cases
  we'll need to go the other way, allow caller to specify whether
  string -> id lookups should be possible on frozen pool.
- On glibc, realloc() to smaller size doesn't move the data but on
  other platforms (including valgrind) it can and does move, which
  would require a full rehash. For now, just leave all the data
  alone unless we're also freeing the hash, the memory savings
  isn't much for a global pool (which is where this matters)

11 years agoAdd getters for rpmds dependency name and EVR pool ids
Panu Matilainen [Wed, 12 Sep 2012 11:38:34 +0000 (14:38 +0300)]
Add getters for rpmds dependency name and EVR pool ids

11 years agoAdd getters for rpmfi base- and directory name pool id's
Panu Matilainen [Wed, 12 Sep 2012 11:38:08 +0000 (14:38 +0300)]
Add getters for rpmfi base- and directory name pool id's

11 years agoPass transaction pool to rpmal (but not used yet)
Panu Matilainen [Wed, 12 Sep 2012 11:33:17 +0000 (14:33 +0300)]
Pass transaction pool to rpmal (but not used yet)

11 years agoActually enable the global transaction string pool
Panu Matilainen [Wed, 12 Sep 2012 10:43:46 +0000 (13:43 +0300)]
Actually enable the global transaction string pool

- With this, practically all transaction member file (base- and dirname)
  and dependency strings get now stored in a giant transaction global
  string pool. Greenpeace applaudes us for all the rain-forests that
  will be saved by the memory savings... not. Some memory is saved
  but the real wins only start when everything is converted to use
  pool id's instead of string pointers. Also we're still creating
  a ridiculous number of private pools from various sources, but
  we gotta start someplace.

11 years agoAdd infastructure for global transaction set string pool
Panu Matilainen [Wed, 12 Sep 2012 10:37:54 +0000 (13:37 +0300)]
Add infastructure for global transaction set string pool

- Add a pool pointer to to ts members struct and a getter function
- Grab the global pool for rpmte dependency- and file info creation,
  if its NULL then the sets will use private pools of their own.
- Add the (currently) required magic voodoo rain-dance to freeze and
  unfreeze the pool as necessary wrt new element additions: for
  current rpmal and fingerprinting to work, the string pointers
  must be immovable.
- This is infrastructure only: nothing creates the global pool yet,
  so everything is still using private pools.

11 years agoString pool id 0 equals NULL
Panu Matilainen [Wed, 12 Sep 2012 10:32:31 +0000 (13:32 +0300)]
String pool id 0 equals NULL

- Pool id 0 is special case for "not found". Return an actual NULL
  instead of an empty string.

11 years agoAvoid doing anything if pool is already frozen
Panu Matilainen [Wed, 12 Sep 2012 10:30:50 +0000 (13:30 +0300)]
Avoid doing anything if pool is already frozen

11 years agoAdd getter methods for rpmds and rpmfi string pool handle
Panu Matilainen [Wed, 12 Sep 2012 09:53:56 +0000 (12:53 +0300)]
Add getter methods for rpmds and rpmfi string pool handle

11 years agoDelay transaction added packages rpmal creation until required
Panu Matilainen [Wed, 12 Sep 2012 09:41:07 +0000 (12:41 +0300)]
Delay transaction added packages rpmal creation until required

- We're not using the added rpmal for anything before rpmtsCheck() and/or
  rpmtsOrder(), so this shouldn't break anything either. This is probably
  a more or less temporary setup to make string pointer -> pool id
  transition a bit easier.

11 years agoAdd an nternal rpmal create+populate helper function, use for erased packages
Panu Matilainen [Wed, 12 Sep 2012 09:30:44 +0000 (12:30 +0300)]
Add an nternal rpmal create+populate helper function, use for erased packages

- We'll need this shortly for added packages too...

11 years agoOops, only private pool should be frozen on ds create
Panu Matilainen [Tue, 11 Sep 2012 11:40:01 +0000 (14:40 +0300)]
Oops, only private pool should be frozen on ds create

11 years agoAdd an alternative rpmds constructor to allow shared pool usage
Panu Matilainen [Tue, 11 Sep 2012 10:53:24 +0000 (13:53 +0300)]
Add an alternative rpmds constructor to allow shared pool usage

- rpmdsNewPool() allows specifying shared/private pool, and rpmdsNew()
  is now just a wrapper to always call it with NULL (ie private) pool.

11 years agoFreeze the rpmlib dependency set pool on successful return
Panu Matilainen [Tue, 11 Sep 2012 10:42:21 +0000 (13:42 +0300)]
Freeze the rpmlib dependency set pool on successful return

- ...to avoid wasting memory on the relatively static data. We could
  handle the rpmlib ds singleton behavior here too but it would change
  semantics. Ponder about it later...
- Would be nicer to have rpmdsMerge() freeze on return, but that
  gets called in loops so we'd be doing a whole lot of huffing and
  puffing recreating the pools on each entry.

11 years agoFurther split single ds creation into two, sigh
Panu Matilainen [Tue, 11 Sep 2012 10:14:04 +0000 (13:14 +0300)]
Further split single ds creation into two, sigh

- Allow rpmdsCurrent() to share the pool and id's of its "parent" ds
  instead of having to repeatedly create and tear down entire pools
  just for a couple of strings. Used by python bindings for rpmds
  iteration so we'll want to be reasonably efficient.
- For now, rpmdsSingle() and rpmdsThis() always get a private pool,
  wasteful as it might be, but at least now we can freeze them.

11 years agoUnify the common parts of rpmds creation into a helper function
Panu Matilainen [Tue, 11 Sep 2012 08:46:19 +0000 (11:46 +0300)]
Unify the common parts of rpmds creation into a helper function

- No functional changes, just sanity-refactoring

11 years agoEliminate assert()'s from rpmdsMerge()
Panu Matilainen [Tue, 11 Sep 2012 08:19:23 +0000 (11:19 +0300)]
Eliminate assert()'s from rpmdsMerge()

- These "can't happen" cases where EVR/Flags in source ds are missing
  are just as easy to handle as is dying, handling is saner...

11 years agoEliminate assert()'s from rpmdsDup()
Panu Matilainen [Tue, 11 Sep 2012 08:00:24 +0000 (11:00 +0300)]
Eliminate assert()'s from rpmdsDup()

- The "can't happen" case where EVR/Flags are not present is just as
  easily handled as dying.

11 years agoSwitch dependency sets to use string pool storage for names and evrs
Panu Matilainen [Tue, 11 Sep 2012 07:41:49 +0000 (10:41 +0300)]
Switch dependency sets to use string pool storage for names and evrs

- Always push dependency names and versions into string pool (private
  for now). This is terribly wasteful for single ds items, even more
  so for rpmdsCurrent() but to keep the initial switch-over changes
  to minimum we'll deal with those later.
- While we freeze the pool for ds data from headers, single ds items
  are on purpose not frozen for now, due to interactions with
  rpmdsCurrent() and rpmds merging.
- Eliminate no longer needed rpmdsDupArgv(), we're now just copying
  a bunch of integers around. Sanitize rpmdsMerge() now that we can:
  realloc and shift the data instead of recreating all of N, EVR
  and Flags.

11 years agoFix segfault on rpmstrPoolId() on frozen pool
Panu Matilainen [Tue, 11 Sep 2012 07:03:51 +0000 (10:03 +0300)]
Fix segfault on rpmstrPoolId() on frozen pool

- String -> id lookups need the hash table in place even if we're not
  adding. We could do a linear search in such a case but...

11 years agoMake rpmstrPoolUnfreeze() safe to call on unfrozen pool
Panu Matilainen [Tue, 11 Sep 2012 06:01:49 +0000 (09:01 +0300)]
Make rpmstrPoolUnfreeze() safe to call on unfrozen pool

11 years agoRename td2pool as rpmtdToPool, export and optimize
Panu Matilainen [Tue, 11 Sep 2012 05:12:49 +0000 (08:12 +0300)]
Rename td2pool as rpmtdToPool, export and optimize

- Using rpmtd iteration for this is slow and stupid as we keep
  pointlessly re-re-re-re-re-validating the tag type and indexes.
- Change argument order to source -> destination
- Move to rpmtd.c where it belongs and make public with a decent
  name. Not sure if this is the kind of an API we really want to make
  public but ... at least for now it'll do.

11 years agoEliminate direct rpmds name (and flags) access on rpmdsNew()
Panu Matilainen [Tue, 11 Sep 2012 05:05:43 +0000 (08:05 +0300)]
Eliminate direct rpmds name (and flags) access on rpmdsNew()

11 years agoClean up rpmdsSearch() a bit
Panu Matilainen [Tue, 11 Sep 2012 04:52:47 +0000 (07:52 +0300)]
Clean up rpmdsSearch() a bit

- Eliminate numerous repeated direct accesses to [o]ds N, EVR and Flags,
  instead use getter functions and local variable for ods name which
  does not change.

11 years agoAdd internal indexed variants of rpmds N, EVR and Flags getters
Panu Matilainen [Tue, 11 Sep 2012 04:40:06 +0000 (07:40 +0300)]
Add internal indexed variants of rpmds N, EVR and Flags getters

- We'll need these to eliminate the remaining direct accesses to
  N, EVR (and Flags) on random access patterns such as rpmdsSearch().

11 years agoClean up rpmdsFind() a bit
Panu Matilainen [Tue, 11 Sep 2012 04:25:04 +0000 (07:25 +0300)]
Clean up rpmdsFind() a bit

- Eliminate numerous repeated direct accesses to [o]ds N, EVR and Flags,
  instead grab them into local variables through getter functions as
  needed: on entry for ods which doesn't change, for ds in the loop
  as we're changing ds->i here.

11 years agoSplit rpmds EVR comparison into function of its own
Panu Matilainen [Tue, 11 Sep 2012 04:23:50 +0000 (07:23 +0300)]
Split rpmds EVR comparison into function of its own

- The EVR comparison is a distinct operation of its own: rpmdsCompare()
  looks at the other properties, EVR comparison is done if needed.
  Doesn't affect speed or functionality, but cuts down on the
  big number of local variables and has the nice side-effect of
  making the xstrdup() allocations local within rpmdsCompareEVR()

11 years agoUse getter functions for name, evr and flags in rpmdsCurrent()
Panu Matilainen [Tue, 11 Sep 2012 03:58:00 +0000 (06:58 +0300)]
Use getter functions for name, evr and flags in rpmdsCurrent()

11 years agoClean up rpmdsCompare() a bit
Panu Matilainen [Tue, 11 Sep 2012 03:54:31 +0000 (06:54 +0300)]
Clean up rpmdsCompare() a bit

- Eliminate numerous repeated direct accesses to ds N, EVR and Flags,
  instead grab them into local variables through getter functions
  as they are needed. Besides making it easier on the eyes, makes the
  function safe(r) wrt illegal iterator values etc.

11 years agoClean up rpmdsNewDNEVR() a bit
Panu Matilainen [Tue, 11 Sep 2012 03:34:36 +0000 (06:34 +0300)]
Clean up rpmdsNewDNEVR() a bit

- Eliminate numerous repeated direct accesses to ds N, EVR and Flags,
  instead grab them into local variables at entry. This also makes
  the function safe illegal iterator values (ie calling when iteration
  not started), previously the bounds were not checked.

11 years agoAnd now, on to the embarrassing string-pool reimplementation bugs, take I
Panu Matilainen [Sun, 9 Sep 2012 09:25:56 +0000 (12:25 +0300)]
And now, on to the embarrassing string-pool reimplementation bugs, take I

- String pool offset resize was off by one, oops
- String pool data-area resize requires rehashing all the strings,
  as the key pointers change. Ouch. Should be avoidable by extending
  rpmhash to allow passing the pool itself around in comparisons as "self"
  and using offsets as keys, but for now working counts more than speed.
- The unfreeze-sizehint calculation could be negative. Turn the initial
  size into constant and use that as a minimum, otherwise rehashing
  uses (more or less arbitrary) heuristics to come up with some number.
  Lots of fine-tuning ahead...

11 years agoSwitch file info set base- and dirnames storage to string pool
Panu Matilainen [Sat, 8 Sep 2012 08:25:16 +0000 (11:25 +0300)]
Switch file info set base- and dirnames storage to string pool

- Always push base and dir names into file info sets string pool,
  whether private or shared. For basenames, this can save significant
  space even in a private pool, for dirnames private pool is moot
  as the names are already unique, shared pool is quite another story.
- Adjust fpLookupList() to take a pool and id's as arguments.
- This introduces a fair amount of overhead, so things will be somewhat
  slower until the transition to pool id's is (more) complete. Sometimes
  things have to get worse before they get better... Other than that,
  this should be entirely invisible to callers.