Project

General

Profile

Actions

Bug #14089

closed

ceph rbd api is not thread safe

Added by ceph zte over 8 years ago. Updated over 8 years ago.

Status:
Duplicate
Priority:
Normal
Assignee:
-
Target version:
-
% Done:

0%

Source:
other
Tags:
Backport:
Regression:
No
Severity:
3 - minor
Reviewed:
Affected Versions:
ceph-qa-suite:
rbd
Pull request ID:
Crash signature (v1):
Crash signature (v2):

Description

My ceph version is 0.94.When i use the Multithreading run rbd api like below.

The librbd will core dump.Why the librbd api is not thread safe?

import rados
import rbd
import hashlib
import datetime
import  threading

RADOS_NAME = 'client.admin'
RBDTIMEOUT = 20
num=0
def md5(raw):
    import hashlib
    hasher = hashlib.md5()
    hasher.update(raw)
    return hasher.hexdigest()

mu = threading.Lock()
mu1 = threading.Lock()

class RBDHandle():
    def __init__(self, clustername="ceph"):
        self._clustername = clustername

    def getmd5info(self, ivalue):
        hasher = hashlib.md5()
        hasher.update(str(ivalue))
        return hasher.hexdigest()

     def testconnect(self):
       try:

           cluster_handle = rados.Rados(name=RADOS_NAME, clustername=self._clustername, conffile='')
           cluster_handle.connect(timeout=RBDTIMEOUT)

       except:
           print "it is error" 
       finally:

           cluster_handle.shutdown()

           if mu1.acquire():
              global num
              num = num + 1
              mu1.release()
              print num

def test_fuc():
    crb = RBDHandle()
    data={}
    threads=[]
    for i in range(1,10):
        print "it is begin" 
        t=threading.Thread(target= crb.testconnect)
        threads.append(t)

    for t in threads:
        t.setDaemon(True)
        t.start()
    t.join()

if __name__ == "__main__":
    while True:
         global num
         num = 0
         test_fuc()
         if num != 9:
            break
    print "it is over" 
Actions

Also available in: Atom PDF