Uploaded image for project: 'Pig'
  1. Pig
  2. PIG-3645

Move FileLocalizer.setR() calls to unit tests

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 0.13.0
    • impl
    • None

    Description

      Currently, temporary paths are generated by FileLocalizer using Random.nextInt(). To provide strong randomness, MapReduceLauncher resets the Random object every time when compiling physical plan to MR plan:

      MRCompiler comp = new MRCompiler(php, pc); 
      comp.randomizeFileLocalizer(); // This in turn calls FileLocalizer.setR(new Random()).
      

      Besides, there are a couple of places calling FileLocalizer.setR() (e.g. MRCompiler) with some random seed.

      I think-

      1. Randomizing Random seed is unnecessary if we switch to UUID.
      2. Setting Random objects in code like this is error-prone because it can be easily broken by having or missing a FileLocalizer.setR() somewhere else. See an example here.

      So I propose that we remove all this "randomizing Random seed" code and use UUID instead in temporary paths.

      For unit tests that compare the results against gold files, we should still allow to set Random seed through FileLocalizer.setR(). But this method will be annotated as "VisibleForTesting" to ensure it is not used nowhere else other than in unit tests.

      Regarding the existing gold files, they can be easily regenerated by TestMRCompiler as follows-

      FileOutputStream fos = new FileOutputStream(expectedFile + "_new");
      PrintWriter pw = new PrintWriter(fos);
      pw.write(compiledPlan);
      

      I assume there won't be any kind of regressions due to this change. But please let me know if I am wrong.

      Attachments

        1. PIG-3645-1.patch
          57 kB
          Cheolsoo Park
        2. PIG-3645-2.patch
          53 kB
          Cheolsoo Park
        3. PIG-3645-3.patch
          53 kB
          Cheolsoo Park
        4. PIG-3645-4.patch
          36 kB
          Cheolsoo Park
        5. TEST-org.apache.pig.test.TestMRCompiler.txt
          277 kB
          Cheolsoo Park

        Activity

          People

            cheolsoo Cheolsoo Park
            cheolsoo Cheolsoo Park
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: