{"record":{"id":"5cd15894db9f68f1","repo":"apolloconfig/apollo","slug":"the-maximum-number-of-items-s-for-this-namespac-5cd158","errorCode":null,"errorMessage":"The maximum number of items (%s) for this namespace has been reached. Current item count is %s.","messagePattern":"The maximum number of items \\((.+?)\\) for this namespace has been reached\\. Current item count is (.+?)\\.","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemSetService.java","lineNumber":78,"sourceCode":"\n  @Transactional\n  public ItemChangeSets updateSet(String appId, String clusterName, String namespaceName,\n      ItemChangeSets changeSet) {\n    Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);\n\n    if (namespace == null) {\n      throw NotFoundException.namespaceNotFound(appId, clusterName, namespaceName);\n    }\n\n    if (bizConfig.isItemNumLimitEnabled()) {\n      int itemCount = itemService.findNonEmptyItemCount(namespace.getId());\n      int createItemCount = (int) changeSet.getCreateItems().stream()\n          .filter(item -> !StringUtils.isEmpty(item.getKey())).count();\n      int deleteItemCount = (int) changeSet.getDeleteItems().stream()\n          .filter(item -> !StringUtils.isEmpty(item.getKey())).count();\n      itemCount = itemCount + createItemCount - deleteItemCount;\n      if (itemCount > bizConfig.itemNumLimit()) {\n        throw new BadRequestException(\"The maximum number of items (\" + bizConfig.itemNumLimit()\n            + \") for this namespace has been reached. Current item count is \" + itemCount + \".\");\n      }\n    }\n\n    String operator = changeSet.getDataChangeLastModifiedBy();\n    ConfigChangeContentBuilder configChangeContentBuilder = new ConfigChangeContentBuilder();\n\n    if (!CollectionUtils.isEmpty(changeSet.getCreateItems())) {\n      this.doCreateItems(changeSet.getCreateItems(), namespace, operator,\n          configChangeContentBuilder);\n      auditService.audit(\"ItemSet\", null, Audit.OP.INSERT, operator);\n    }\n\n    if (!CollectionUtils.isEmpty(changeSet.getUpdateItems())) {\n      this.doUpdateItems(changeSet.getUpdateItems(), namespace, operator,\n          configChangeContentBuilder);\n      auditService.audit(\"ItemSet\", null, Audit.OP.UPDATE, operator);\n    }","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemSetService.java#L60-L96","documentation":"Thrown as BadRequestException (HTTP 400) by ItemSetService when a batch item create/update/delete would push a namespace's non-empty item count above the configured item.num.limit. The limit is only enforced when bizConfig.isItemNumLimitEnabled() is true. The check accounts for items being added minus items being deleted in the same change set, so it is the projected post-change count that matters.","triggerScenarios":"Calling a bulk item update endpoint (ItemSetService.updateItemsWithinNamespace) when itemNumLimitEnabled=true and (existing non-empty item count + new items with non-empty keys - deleted items with non-empty keys) exceeds itemNumLimit(). Typical entry point: portal/admin item batch save or OpenAPI mass import.","commonSituations":"Bulk importing a large properties file or many config items into one namespace; splitting a monolithic config into Apollo without raising the limit; environments where ops enabled the item limit with a low default.","solutions":["Raise the limit in portal admin config: set item.num.limit to a higher value (and ensure item.num.limit.enabled=true only if you intend enforcement).","Split the configuration across multiple namespaces or apps instead of one large namespace.","Delete obsolete/empty-key items first so the projected count stays under the limit within the same change set."],"exampleFix":"// before: one namespace holding 2000+ keys\n// after: raise limit via admin config, or partition\n# apollo portal DB / admin config\nitem.num.limit.enabled = true\nitem.num.limit = 5000","handlingStrategy":"validation","validationCode":"int existing = itemService.findNonEmptyItemCount(namespace.getId());\nint add = (int) changeSet.getCreateItems().stream()\n    .filter(i -> !StringUtils.isEmpty(i.getKey())).count();\nint del = (int) changeSet.getDeleteItems().stream()\n    .filter(i -> !StringUtils.isEmpty(i.getKey())).count();\nint projected = existing + add - del;\nif (bizConfig.isItemNumLimitEnabled() && projected > bizConfig.itemNumLimit()) {\n  // abort or split before calling ItemSetService\n}","typeGuard":null,"tryCatchPattern":"try {\n  itemSetService.updateSet(appId, clusterName, namespaceName, changeSet);\n} catch (BadRequestException e) {\n  if (e.getMessage().contains(\"maximum number of items\")) {\n    // split change set or surface quota guidance\n  } else { throw e; }\n}","preventionTips":["Monitor non-empty item counts per namespace against item.num.limit.","Partition large configs into multiple namespaces at design time.","Pre-validate batch imports with the same add-minus-delete arithmetic the service uses."],"tags":["config","item-limit","bad-request","apollo-biz","validation"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}