Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/core/cm/launcher/idpool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ static constexpr auto cGIDRangeEnd = 10000;

/**
* Max number of locked GIDs simultaneously.
* Double the number of update items to avoid exhausting the range when removing instances.
*/
static constexpr auto cMaxNumLockedGIDs = cMaxNumUpdateItems;
static constexpr auto cMaxNumLockedGIDs = 2 * cMaxNumUpdateItems;

/**
* UID range start.
Expand All @@ -43,8 +44,9 @@ static constexpr auto cUIDRangeEnd = 10000;

/**
* Max number of locked UIDs simultaneously.
* Double the number of update items to avoid exhausting the range when removing instances.
*/
static constexpr auto cMaxNumLockedUIDs = cMaxNumInstances;
static constexpr auto cMaxNumLockedUIDs = 2 * cMaxNumInstances;

/**
* Pool that manages identifiers with reference counting per key.
Expand Down Expand Up @@ -166,10 +168,9 @@ class IDPool {
StaticMap<K, ItemEntry, cMaxNumItems> mItems;
};

using GIDPool
= IDPool<StaticString<cIDLen>, gid_t, cGIDRangeBegin, cGIDRangeEnd, cMaxNumLockedGIDs, cMaxNumUpdateItems>;
using GIDPool = IDPool<StaticString<cIDLen>, gid_t, cGIDRangeBegin, cGIDRangeEnd, cMaxNumLockedGIDs, cMaxNumLockedGIDs>;

using UIDPool = IDPool<InstanceIdent, uid_t, cUIDRangeBegin, cUIDRangeEnd, cMaxNumLockedUIDs, cMaxNumInstances>;
using UIDPool = IDPool<InstanceIdent, uid_t, cUIDRangeBegin, cUIDRangeEnd, cMaxNumLockedUIDs, cMaxNumLockedUIDs>;

} // namespace aos::cm::launcher

Expand Down
18 changes: 13 additions & 5 deletions src/core/cm/launcher/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,24 +408,32 @@
{
LOG_DBG() << "Remove instance" << Log::Field("instanceID", mInfo.mInstanceIdent);

Error firstErr = ErrorEnum::eNone;

if (auto err = mStorageState.Remove(mInfo.mInstanceIdent); !err.IsNone() && !err.Is(ErrorEnum::eNotFound)) {
return AOS_ERROR_WRAP(err);
firstErr = AOS_ERROR_WRAP(err);
}

if (auto err = mStorage.RemoveInstance(mInfo.mInstanceIdent, mInfo.mVersion);
!err.IsNone() && !err.Is(ErrorEnum::eNotFound)) {
return AOS_ERROR_WRAP(err);
if (firstErr.IsNone()) {

Check warning on line 419 in src/core/cm/launcher/instance.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge this "if" statement with the enclosing one.

See more on https://sonarcloud.io/project/issues?id=aosedge_aos_core_lib_cpp&issues=AZ-kLoEbGDwGrdqdfKlu&open=AZ-kLoEbGDwGrdqdfKlu&pullRequest=633
firstErr = AOS_ERROR_WRAP(err);
}
}

if (auto err = mUIDPool.Release(mInfo.mInstanceIdent); !err.IsNone() && !err.Is(ErrorEnum::eNotFound)) {
return AOS_ERROR_WRAP(err);
if (firstErr.IsNone()) {

Check warning on line 425 in src/core/cm/launcher/instance.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge this "if" statement with the enclosing one.

See more on https://sonarcloud.io/project/issues?id=aosedge_aos_core_lib_cpp&issues=AZ-kLoEbGDwGrdqdfKlv&open=AZ-kLoEbGDwGrdqdfKlv&pullRequest=633
firstErr = AOS_ERROR_WRAP(err);
}
}

if (auto err = mGIDPool.Release(mInfo.mInstanceIdent.mItemID); !err.IsNone() && !err.Is(ErrorEnum::eNotFound)) {
return AOS_ERROR_WRAP(err);
if (firstErr.IsNone()) {

Check warning on line 431 in src/core/cm/launcher/instance.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge this "if" statement with the enclosing one.

See more on https://sonarcloud.io/project/issues?id=aosedge_aos_core_lib_cpp&issues=AZ-kLoEbGDwGrdqdfKlw&open=AZ-kLoEbGDwGrdqdfKlw&pullRequest=633
firstErr = AOS_ERROR_WRAP(err);
}
}

return ErrorEnum::eNone;
return firstErr;
}

Error ServiceInstance::Cache(bool disable)
Expand Down
6 changes: 3 additions & 3 deletions src/core/cm/launcher/instancemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,11 @@ RetWithError<SharedPtr<Instance>> InstanceManager::CreateInstance(const Instance

if (auto err = newInstance->Init(); !err.IsNone()) {
// Do not leave invalid instance in storage.
if (err = newInstance->Remove(); !err.IsNone()) {
LOG_ERR() << "Can't remove instance" << Log::Field(err);
if (auto rmErr = newInstance->Remove(); !rmErr.IsNone()) {
LOG_ERR() << "Can't remove instance" << Log::Field(AOS_ERROR_WRAP(rmErr));
}

return {{}, AOS_ERROR_WRAP(err)};
return {nullptr, err};
}

if (auto [_, err] = newInstance->OverrideEnvVars(mEnvVarsOverrides); !err.IsNone()) {
Expand Down
Loading