function moveToExternal($cluster, $maxID)
{
    $fname = 'moveToExternal';
    $dbw =& wfGetDB(DB_MASTER);
    print "Moving {$maxID} text rows to external storage\n";
    $ext = new ExternalStoreDB();
    for ($id = 1; $id <= $maxID; $id++) {
        if (!($id % REPORTING_INTERVAL)) {
            print "{$id}\n";
            wfWaitForSlaves(5);
        }
        $row = $dbw->selectRow('text', array('old_flags', 'old_text'), array('old_id' => $id, "old_flags NOT LIKE '%external%'"), $fname);
        if (!$row) {
            # Non-existent or already done
            continue;
        }
        # Resolve stubs
        $flags = explode(',', $row->old_flags);
        if (in_array('object', $flags) && substr($row->old_text, 0, strlen(STUB_HEADER)) === STUB_HEADER) {
            resolveStub($id, $row->old_text, $row->old_flags);
            continue;
        }
        $url = $ext->store($cluster, $row->old_text);
        if (!$url) {
            print "Error writing to external storage\n";
            exit;
        }
        if ($row->old_flags === '') {
            $flags = 'external';
        } else {
            $flags = "{$row->old_flags},external";
        }
        $dbw->update('text', array('old_flags' => $flags, 'old_text' => $url), array('old_id' => $id), $fname);
    }
}
Beispiel #2
0
function moveToExternal($cluster, $maxID)
{
    $fname = 'moveToExternal';
    $dbw =& wfGetDB(DB_MASTER);
    print "Moving {$maxID} text rows to external storage\n";
    $ext = new ExternalStoreDB();
    for ($id = 1; $id <= $maxID; $id++) {
        if (!($id % REPORTING_INTERVAL)) {
            print "{$id}\n";
            wfWaitForSlaves(5);
        }
        $row = $dbw->selectRow('text', array('old_flags', 'old_text'), array('old_id' => $id, "old_flags NOT LIKE '%external%'"), $fname);
        if (!$row) {
            # Non-existent or already done
            continue;
        }
        # Resolve stubs
        $text = $row->old_text;
        if ($row->old_flags === '') {
            $flags = 'external';
        } else {
            $flags = "{$row->old_flags},external";
        }
        if (strpos($flags, 'object') !== false) {
            $obj = unserialize($text);
            $className = strtolower(get_class($obj));
            if ($className == 'historyblobstub') {
                resolveStub($id, $row->old_text, $row->old_flags);
                continue;
            } elseif ($className == 'historyblobcurstub') {
                $text = gzdeflate($obj->getText());
                $flags = 'utf-8,gzip,external';
            } elseif ($className == 'concatenatedgziphistoryblob') {
                // Do nothing
            } else {
                print "Warning: unrecognised object class \"{$className}\"\n";
                continue;
            }
        }
        if (strlen($text) < 100) {
            // Don't move tiny revisions
            continue;
        }
        #print "Storing "  . strlen( $text ) . " bytes to $url\n";
        $url = $ext->store($cluster, $text);
        if (!$url) {
            print "Error writing to external storage\n";
            exit;
        }
        $dbw->update('text', array('old_flags' => $flags, 'old_text' => $url), array('old_id' => $id), $fname);
    }
}
Beispiel #3
0
/**
 * Convert history stubs that point to an external row to direct
 * external pointers
 */
function resolveStubs()
{
    $fname = 'resolveStubs';
    $dbr = wfGetDB(DB_SLAVE);
    $maxID = $dbr->selectField('text', 'MAX(old_id)', false, $fname);
    $blockSize = 10000;
    $numBlocks = intval($maxID / $blockSize) + 1;
    for ($b = 0; $b < $numBlocks; $b++) {
        wfWaitForSlaves(2);
        printf("%5.2f%%\n", $b / $numBlocks * 100);
        $start = intval($maxID / $numBlocks) * $b + 1;
        $end = intval($maxID / $numBlocks) * ($b + 1);
        $res = $dbr->select('text', array('old_id', 'old_text', 'old_flags'), "old_id>={$start} AND old_id<={$end} " . "AND old_flags LIKE '%object%' AND old_flags NOT LIKE '%external%' " . 'AND LOWER(CONVERT(LEFT(old_text,22) USING latin1)) = \'o:15:"historyblobstub"\'', $fname);
        foreach ($res as $row) {
            resolveStub($row->old_id, $row->old_text, $row->old_flags);
        }
    }
    print "100%\n";
}
Beispiel #4
0
/**
 * Convert history stubs that point to an external row to direct
 * external pointers
 */
function resolveStubs()
{
    $fname = 'resolveStubs';
    $dbr = wfGetDB(DB_SLAVE);
    $maxID = $dbr->selectField('text', 'MAX(old_id)', false, $fname);
    $blockSize = 10000;
    $numBlocks = intval($maxID / $blockSize) + 1;
    for ($b = 0; $b < $numBlocks; $b++) {
        wfWaitForSlaves(2);
        printf("%5.2f%%\n", $b / $numBlocks * 100);
        $start = intval($maxID / $numBlocks) * $b + 1;
        $end = intval($maxID / $numBlocks) * ($b + 1);
        $res = $dbr->select('text', array('old_id', 'old_text', 'old_flags'), "old_id>={$start} AND old_id<={$end} " . "AND old_flags='object' " . "AND LOWER(LEFT(old_text,22)) = 'O:15:\"historyblobstub\"'", $fname);
        while ($row = $dbr->fetchObject($res)) {
            resolveStub($row->old_id, $row->old_text, $row->old_flags);
        }
        $dbr->freeResult($res);
    }
    print "100%\n";
}