enh: user dropped notification
This commit is contained in:
parent
13e8a79294
commit
2b25982495
|
@ -125,7 +125,8 @@ typedef enum {
|
|||
|
||||
typedef enum {
|
||||
TAOS_NOTIFY_PASSVER = 0,
|
||||
TAOS_NOTIFY_WHITELIST_VER = 1
|
||||
TAOS_NOTIFY_WHITELIST_VER = 1,
|
||||
TAOS_NOTIFY_USER_DROPPED = 2,
|
||||
} TAOS_NOTIFY_TYPE;
|
||||
|
||||
#define RET_MSG_LENGTH 1024
|
||||
|
|
|
@ -959,7 +959,7 @@ typedef struct {
|
|||
int8_t superAuth;
|
||||
int8_t sysInfo;
|
||||
int8_t enable;
|
||||
int8_t reserve;
|
||||
int8_t dropped;
|
||||
SHashObj* createdDbs;
|
||||
SHashObj* readDbs;
|
||||
SHashObj* writeDbs;
|
||||
|
|
|
@ -133,7 +133,9 @@ typedef struct {
|
|||
int32_t ver;
|
||||
void* param;
|
||||
__taos_notify_fn_t fp;
|
||||
} SPassInfo;
|
||||
} STscNotifyInfo;
|
||||
|
||||
typedef STscNotifyInfo SPassInfo;
|
||||
|
||||
typedef struct {
|
||||
int64_t ver;
|
||||
|
@ -159,6 +161,7 @@ typedef struct STscObj {
|
|||
SHashObj* pRequests;
|
||||
SPassInfo passInfo;
|
||||
SWhiteListInfo whiteListInfo;
|
||||
STscNotifyInfo userDroppedInfo;
|
||||
} STscObj;
|
||||
|
||||
typedef struct STscDbg {
|
||||
|
|
|
@ -96,6 +96,19 @@ static int32_t hbUpdateUserAuthInfo(SAppHbMgr *pAppHbMgr, SUserAuthBatchRsp *bat
|
|||
}
|
||||
}
|
||||
|
||||
if (pRsp->dropped == 1) {
|
||||
if (pTscObj->userDroppedInfo.fp) {
|
||||
SPassInfo *dropInfo = &pTscObj->userDroppedInfo;
|
||||
if (dropInfo->fp) {
|
||||
(*dropInfo->fp)(dropInfo->param, NULL, TAOS_NOTIFY_USER_DROPPED);
|
||||
}
|
||||
}
|
||||
releaseTscObj(pReq->connKey.tscRid);
|
||||
// delete the tscObj
|
||||
releaseTscObj(pReq->connKey.tscRid);
|
||||
continue;
|
||||
}
|
||||
|
||||
pTscObj->authVer = pRsp->version;
|
||||
|
||||
if (pTscObj->sysInfo != pRsp->sysInfo) {
|
||||
|
|
|
@ -147,6 +147,13 @@ int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t fp, void *param, int type)
|
|||
taosThreadMutexUnlock(&pObj->mutex);
|
||||
break;
|
||||
}
|
||||
case TAOS_NOTIFY_USER_DROPPED: {
|
||||
taosThreadMutexLock(&pObj->mutex);
|
||||
pObj->userDroppedInfo.fp = fp;
|
||||
pObj->userDroppedInfo.param = param;
|
||||
taosThreadMutexUnlock(&pObj->mutex);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
releaseTscObj(*(int64_t *)taos);
|
||||
|
|
|
@ -1652,7 +1652,7 @@ int32_t tSerializeSGetUserAuthRspImpl(SEncoder *pEncoder, SGetUserAuthRsp *pRsp)
|
|||
if (tEncodeI8(pEncoder, pRsp->superAuth) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pRsp->sysInfo) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pRsp->enable) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pRsp->reserve) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pRsp->dropped) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, pRsp->version) < 0) return -1;
|
||||
|
||||
int32_t numOfCreatedDbs = taosHashGetSize(pRsp->createdDbs);
|
||||
|
@ -1767,7 +1767,7 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs
|
|||
if (tDecodeI8(pDecoder, &pRsp->superAuth) < 0) goto _err;
|
||||
if (tDecodeI8(pDecoder, &pRsp->sysInfo) < 0) goto _err;
|
||||
if (tDecodeI8(pDecoder, &pRsp->enable) < 0) goto _err;
|
||||
if (tDecodeI8(pDecoder, &pRsp->reserve) < 0) goto _err;
|
||||
if (tDecodeI8(pDecoder, &pRsp->dropped) < 0) goto _err;
|
||||
if (tDecodeI32(pDecoder, &pRsp->version) < 0) goto _err;
|
||||
|
||||
int32_t numOfCreatedDbs = 0;
|
||||
|
|
|
@ -2289,6 +2289,11 @@ int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_
|
|||
for (int32_t i = 0; i < numOfUses; ++i) {
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pUsers[i].user);
|
||||
if (pUser == NULL) {
|
||||
if (TSDB_CODE_MND_USER_NOT_EXIST == terrno) {
|
||||
SGetUserAuthRsp rsp = {.dropped = 1};
|
||||
memcpy(rsp.user, pUsers[i].user, TSDB_USER_LEN);
|
||||
taosArrayPush(batchRsp.pArray, &rsp);
|
||||
}
|
||||
mError("user:%s, failed to auth user since %s", pUsers[i].user, terrstr());
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -47,8 +47,10 @@ typedef uint16_t VarDataLenT;
|
|||
void createUsers(TAOS *taos, const char *host, char *qstr);
|
||||
void passVerTestMulti(const char *host, char *qstr);
|
||||
void sysInfoTest(TAOS *taos, const char *host, char *qstr);
|
||||
void userDroppedTest(TAOS *taos, const char *host, char *qstr);
|
||||
|
||||
int nPassVerNotified = 0;
|
||||
int nUserDropped = 0;
|
||||
TAOS *taosu[nRoot] = {0};
|
||||
char users[nUser][USER_LEN] = {0};
|
||||
|
||||
|
@ -56,11 +58,16 @@ void __taos_notify_cb(void *param, void *ext, int type) {
|
|||
switch (type) {
|
||||
case TAOS_NOTIFY_PASSVER: {
|
||||
++nPassVerNotified;
|
||||
printf("%s:%d type:%d user:%s ver:%d\n", __func__, __LINE__, type, param ? (char *)param : "NULL", *(int *)ext);
|
||||
printf("%s:%d type:%d user:%s passVer:%d\n", __func__, __LINE__, type, param ? (char *)param : "NULL", *(int *)ext);
|
||||
break;
|
||||
}
|
||||
case TAOS_NOTIFY_USER_DROPPED: {
|
||||
++nUserDropped;
|
||||
printf("%s:%d type:%d user:%s dropped\n", __func__, __LINE__, type, param ? (char *)param : "NULL");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
printf("%s:%d unknown type:%d\n", __func__, __LINE__, type);
|
||||
printf("%s:%d unknown notify type:%d\n", __func__, __LINE__, type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -201,7 +208,8 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
createUsers(taos, argv[1], qstr);
|
||||
passVerTestMulti(argv[1], qstr);
|
||||
sysInfoTest(taos, argv[1], qstr);
|
||||
// sysInfoTest(taos, argv[1], qstr);
|
||||
userDroppedTest(taos, argv[1], qstr);
|
||||
|
||||
taos_close(taos);
|
||||
taos_cleanup();
|
||||
|
@ -223,9 +231,16 @@ void createUsers(TAOS *taos, const char *host, char *qstr) {
|
|||
int code = taos_set_notify_cb(taosu[i], __taos_notify_cb, users[i], TAOS_NOTIFY_PASSVER);
|
||||
|
||||
if (code != 0) {
|
||||
fprintf(stderr, "failed to run: taos_set_notify_cb for user:%s since %d\n", users[i], code);
|
||||
fprintf(stderr, "failed to run: taos_set_notify_cb(TAOS_NOTIFY_PASSVER) for user:%s since %d\n", users[i], code);
|
||||
} else {
|
||||
fprintf(stderr, "success to run: taos_set_notify_cb for user:%s\n", users[i]);
|
||||
fprintf(stderr, "success to run: taos_set_notify_cb(TAOS_NOTIFY_PASSVER) for user:%s\n", users[i]);
|
||||
}
|
||||
|
||||
code = taos_set_notify_cb(taosu[i], __taos_notify_cb, users[i], TAOS_NOTIFY_USER_DROPPED);
|
||||
if (code != 0) {
|
||||
fprintf(stderr, "failed to run: taos_set_notify_cb(TAOS_NOTIFY_USER_DROPPED) for user:%s since %d\n", users[i], code);
|
||||
} else {
|
||||
fprintf(stderr, "success to run: taos_set_notify_cb(TAOS_NOTIFY_USER_DROPPED) for user:%s\n", users[i]);
|
||||
}
|
||||
|
||||
// alter pass for users
|
||||
|
@ -301,6 +316,7 @@ void passVerTestMulti(const char *host, char *qstr) {
|
|||
}
|
||||
|
||||
void sysInfoTest(TAOS *taosRoot, const char *host, char *qstr) {
|
||||
fprintf(stderr, "######## %s entry #########\n", __func__);
|
||||
TAOS *taos[nRoot] = {0};
|
||||
char userName[USER_LEN] = "user0";
|
||||
|
||||
|
@ -377,3 +393,47 @@ _REP:
|
|||
fprintf(stderr, ">>> succeed to run sysInfoTest\n");
|
||||
fprintf(stderr, "######## %s #########\n", __func__);
|
||||
}
|
||||
|
||||
void userDroppedTest(TAOS *taos, const char *host, char *qstr) {
|
||||
// users
|
||||
int nTestUsers = 1; // nUser
|
||||
for (int i = 0; i < nTestUsers; ++i) {
|
||||
// sprintf(users[i], "user%d", i);
|
||||
taosu[i] = taos_connect(host, users[i], "taos", NULL, 0);
|
||||
if (taosu[i] == NULL) {
|
||||
printf("failed to connect to server, user:%s, reason:%s\n", users[i], "null taos" /*taos_errstr(taos)*/);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < nTestUsers; ++i) {
|
||||
// drop user0 ... user${nUser}
|
||||
sprintf(qstr, "drop user %s", users[i]);
|
||||
queryDB(taos, qstr);
|
||||
}
|
||||
|
||||
// calculate the nUserDropped for users
|
||||
int nConn = nTestUsers;
|
||||
|
||||
for (int i = 0; i < 15; ++i) {
|
||||
printf("%s:%d [%d] second(s) elasped, passVer notification received:%d, total:%d\n", __func__, __LINE__, i,
|
||||
nUserDropped, nConn);
|
||||
if (nUserDropped >= nConn) break;
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < nTestUsers; ++i) {
|
||||
taos_close(taosu[i]);
|
||||
printf("%s:%d close taosu[%d]\n", __func__, __LINE__, i);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
fprintf(stderr, "######## %s #########\n", __func__);
|
||||
if (nUserDropped >= nConn) {
|
||||
fprintf(stderr, ">>> succeed to get user dropped notification since nNotify %d >= nConn %d\n", nUserDropped, nConn);
|
||||
} else {
|
||||
fprintf(stderr, ">>> failed to get user dropped notification since nNotify %d < nConn %d\n", nUserDropped, nConn);
|
||||
}
|
||||
fprintf(stderr, "######## %s #########\n", __func__);
|
||||
sleep(300);
|
||||
}
|
Loading…
Reference in New Issue