Пример #1
0
def loadSplitPointsFromMeta(metaUri):
    if not metaUri.startswith('meta+'):
        raise ValueError('not a meta table: %r' % metaUri)
    metaUri = metaUri[5:]
    
    import urllib,cgi
    p,q = urllib.splitquery(metaUri)
    q = cgi.parse_qs(q or '')
    tableName = q.get('name',[''])[0]

    if not tableName:
        raise ValueError('meta uri needs table name')

    from util.zero import zeroEncode,zeroDecode
    pred = '%r <= row < %r and column = "location"' % \
        (zeroEncode(tableName, '\x01', ''),
         zeroEncode(tableName, '\x02', ''))

    rows = []
    import pykdi
    for r,c,t,v in pykdi.Table(metaUri).scan(pred):
        n,x,r = zeroDecode(r)
        rows.append(r)

    f = 1.0 / (len(rows) + 1)
    return [((i+1)*f, r) for i,r in enumerate(rows)]
Пример #2
0
Файл: splits.py Проект: crnt/kdi
def loadSplitPointsFromMeta(metaUri):
    if not metaUri.startswith('meta+'):
        raise ValueError('not a meta table: %r' % metaUri)
    metaUri = metaUri[5:]

    import urllib, cgi
    p, q = urllib.splitquery(metaUri)
    q = cgi.parse_qs(q or '')
    tableName = q.get('name', [''])[0]

    if not tableName:
        raise ValueError('meta uri needs table name')

    from util.zero import zeroEncode, zeroDecode
    pred = '%r <= row < %r and column = "location"' % \
        (zeroEncode(tableName, '\x01', ''),
         zeroEncode(tableName, '\x02', ''))

    rows = []
    import pykdi
    for r, c, t, v in pykdi.Table(metaUri).scan(pred):
        n, x, r = zeroDecode(r)
        rows.append(r)

    f = 1.0 / (len(rows) + 1)
    return [((i + 1) * f, r) for i, r in enumerate(rows)]
Пример #3
0
def main():
    import optparse
    op = optparse.OptionParser()
    op.add_option('-m', '--meta', help='Location of META table')
    op.add_option('-n',
                  '--dryrun',
                  action='store_true',
                  help="Print but don't do")
    opt, args = op.parse_args()

    if not opt.meta:
        op.error('need --meta')

    meta = pykdi.Table(opt.meta)
    scan = meta.scan('column = "config"')

    if opt.dryrun:
        meta.set = makeEcho('meta.set')
        meta.erase = makeEcho('meta.erase')
        meta.sync = makeEcho('meta.sync')

    lastMatch = None
    joinMin = None
    sameKeys = []
    for r, c, t, v in scan:
        if opt.dryrun:
            print 'scan:', (r, c, t, v)

        table = zeroDecode(r)[0]
        server, minRow, frags = parseConfig(v)

        match = table, server, frags
        if match != lastMatch:
            if len(sameKeys) > 1:
                joinTablets(meta, sameKeys, lastMatch[1], joinMin,
                            lastMatch[2])
            joinMin = minRow
            sameKeys = []

        sameKeys.append((r, c, t))
        lastMatch = match

    if len(sameKeys) > 1:
        joinTablets(meta, sameKeys, lastMatch[1], joinMin, lastMatch[2])

    meta.sync()
Пример #4
0
def main():
    import optparse
    op = optparse.OptionParser()
    op.add_option('-m','--meta',help='Location of META table')
    op.add_option('-n','--dryrun',action='store_true',
                  help="Print but don't do")
    opt,args = op.parse_args()

    if not opt.meta:
        op.error('need --meta')

    meta = pykdi.Table(opt.meta)
    scan = meta.scan('column = "config"')

    if opt.dryrun:
        meta.set = makeEcho('meta.set')
        meta.erase = makeEcho('meta.erase')
        meta.sync = makeEcho('meta.sync')
    
    lastMatch = None
    joinMin = None
    sameKeys = []
    for r,c,t,v in scan:
        if opt.dryrun:
            print 'scan:', (r,c,t,v)

        table = zeroDecode(r)[0]
        server,minRow,frags = parseConfig(v)

        match = table,server,frags
        if match != lastMatch:
            if len(sameKeys) > 1:
                joinTablets(meta, sameKeys, lastMatch[1], joinMin,
                            lastMatch[2])
            joinMin = minRow
            sameKeys = []

        sameKeys.append((r,c,t))
        lastMatch = match

    if len(sameKeys) > 1:
        joinTablets(meta, sameKeys, lastMatch[1], joinMin, lastMatch[2])

    meta.sync()
Пример #5
0
def updateLocations(meta, port):
    import pykdi
    from util.props import Properties
    from cStringIO import StringIO
    from util.zero import zeroDecode

    # Open META table
    metaTable = pykdi.Table(meta)

    # Go through 'config' cells, extract 'server' variable, and write
    # 'location' cells
    for row,col,time,val in metaTable.scan('column = "config"'):
        table,dummy,last = zeroDecode(row)
        cfg = Properties(StringIO(val))
        loc = 'kdi://%s:%s/%s' % (cfg.get('server'), port, table)
        metaTable.set(row, 'location', time, loc)
    
    # Sync changes
    metaTable.sync()