Mkcc.pm and mkvob

  • Posted on
  • by
  • in
  • Pulled out common code from mkview that will be needed for mkvob into Mkcc.pm Perl module
  • Re-engineered mkview to use Mkcc.pm
  • Started recoding mkvob to use GPDB and the new Mkcc.pm
  • Code complete on mkvob - need to test
  • Issue: It seems that we have multiple versions of mkview_linked and that UK has continued development of their version of mkview_linked while we've been developing on mkview_linked here in Dallas. IOW there are two versions in separate vobs!

The old mkvob_db

There are some oddities in the old mkvob_db code. For example, there is an insistence in setting umask to 0 before creating directories, which are created with specific permissions. Setting umask is only for the new creation of a directory or file. One could, instead, simply make the directory then chmod it to whatever you really wanted the permissions to be. The new subroutine MakeDir in Mkcc.pm does just that, as well as chown if owner and group are passed in as well as only making the directory if it is needed. This simplifies the code a lot and removes the need to save, set and restore umask.

Another oddity of the old code can be seen in the following:

foreach $rgn (@regionList) {
  $debug && print "DEBUG: Checking tag in $rgn\n";

  $cmd = 'lsvob -s -region $rgn';

  @output = ctcmd($cmd);

  foreach $item (@output)
  {
    if ($item =~ /^$tag$/)
      {
	print "VOB tag $tag already exists in $rgn\n\n";
	exit (1);
      }
  }
}

Looks innocuous enough - run through a list of regions looking to see if this newly requested vob tag already exists in any of the regions. However there are bugs and inefficiencies in the above code. For starters the single quote on the setting of $cmd says to not expand the variable $rgn. The resulting command then becomes "cleartool lsvob -s region $rgn" which, of course, would return an error, which, of course, is not checked for here. So the code, while trying to verify that this vob tag does not exist in any of the regions, fails to actually check it!

However if we just correct that by using double quotes we will now incur a performance penalty. Now the registry server will be required to return all the vob tags for each and every region which can take some time. Is there any way we can make this faster? Why yes there is! Specify the actual vob tag (as in cleartool lsvob -s -region <region name> <vob tag>)! You know sometimes people say that Clearcase always returns all of the registry data which is then parsed locally. Then again, sometimes it's the programmer who asks for it!

So the new code looks like:

foreach (@regionList) {
  debug "Checking for $tag in region $_";

  @output = ctcmd "lsvob -s -region $_ $tag";

  error "VOB tag $tag already exists in region $_", 1 if !grep /Error/, @output;
} # foreach

Note the simplifications for debug (now a subroutine from Mkcc.pm), usage of the default variable ($_) and error reporting (also a subroutine from Mkcc.pm). This algorithm performs the same task, correctly and orders of magnitude quicker.