ATLAS-2729: fix - audit logging fails for large entities

(cherry picked from commit 92f3a91ec56538305043ba0980d3f7a8b477ec96)


Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/c542deb6
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/c542deb6
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/c542deb6

Branch: refs/heads/branch-1.0
Commit: c542deb6d6bbc47a806525aa456b8ea522bd97f4
Parents: 80f0ef4
Author: Madhan Neethiraj <mad...@apache.org>
Authored: Thu May 31 14:22:52 2018 -0700
Committer: Madhan Neethiraj <mad...@apache.org>
Committed: Sun Jun 3 23:27:17 2018 -0700

----------------------------------------------------------------------
 .../repository/audit/EntityAuditListener.java   | 11 +++++++++
 .../repository/audit/EntityAuditListenerV2.java | 25 +++++++++++++++++++-
 2 files changed, 35 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/c542deb6/repository/src/main/java/org/apache/atlas/repository/audit/EntityAuditListener.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/audit/EntityAuditListener.java
 
b/repository/src/main/java/org/apache/atlas/repository/audit/EntityAuditListener.java
index 27d121a..dfacb38 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/audit/EntityAuditListener.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/audit/EntityAuditListener.java
@@ -187,6 +187,17 @@ public class EntityAuditListener implements 
EntityChangeListener {
             entity.setValues(null);
 
             auditString = auditPrefix + AtlasType.toV1Json(entity);
+            auditBytes  = auditString.getBytes(StandardCharsets.UTF_8); // 
recheck auditString size
+            auditSize   = auditBytes != null ? auditBytes.length : 0;
+
+            if (auditMaxSize >= 0 && auditSize > auditMaxSize) { // don't 
store classifications as well
+                LOG.warn("audit record still too long: entityType={}, guid={}, 
size={}; maxSize={}. audit will have only summary details",
+                        entity.getTypeName(), entity.getId()._getId(), 
auditSize, auditMaxSize);
+
+                Referenceable shallowEntity = new 
Referenceable(entity.getId(), entity.getTypeName(), null, 
entity.getSystemAttributes(), null, null);
+
+                auditString = auditPrefix + AtlasType.toJson(shallowEntity);
+            }
 
             entity.setValues(attrValues);
         }

http://git-wip-us.apache.org/repos/asf/atlas/blob/c542deb6/repository/src/main/java/org/apache/atlas/repository/audit/EntityAuditListenerV2.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/audit/EntityAuditListenerV2.java
 
b/repository/src/main/java/org/apache/atlas/repository/audit/EntityAuditListenerV2.java
index fe584e3..91e1f63 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/audit/EntityAuditListenerV2.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/audit/EntityAuditListenerV2.java
@@ -234,13 +234,36 @@ public class EntityAuditListenerV2 implements 
EntityChangeListenerV2 {
             LOG.warn("audit record too long: entityType={}, guid={}, size={}; 
maxSize={}. entity attribute values not stored in audit",
                     entity.getTypeName(), entity.getGuid(), auditSize, 
auditMaxSize);
 
-            Map<String, Object> attrValues = entity.getAttributes();
+            Map<String, Object> attrValues    = entity.getAttributes();
+            Map<String, Object> relAttrValues = 
entity.getRelationshipAttributes();
 
             entity.setAttributes(null);
+            entity.setRelationshipAttributes(null);
 
             auditString = auditPrefix + AtlasType.toJson(entity);
+            auditBytes  = auditString.getBytes(StandardCharsets.UTF_8); // 
recheck auditString size
+            auditSize   = auditBytes != null ? auditBytes.length : 0;
+
+            if (auditMaxSize >= 0 && auditSize > auditMaxSize) { // don't 
store classifications and meanings as well
+                LOG.warn("audit record still too long: entityType={}, guid={}, 
size={}; maxSize={}. audit will have only summary details",
+                        entity.getTypeName(), entity.getGuid(), auditSize, 
auditMaxSize);
+
+                AtlasEntity shallowEntity = new AtlasEntity();
+
+                shallowEntity.setGuid(entity.getGuid());
+                shallowEntity.setTypeName(entity.getTypeName());
+                shallowEntity.setCreateTime(entity.getCreateTime());
+                shallowEntity.setUpdateTime(entity.getUpdateTime());
+                shallowEntity.setCreatedBy(entity.getCreatedBy());
+                shallowEntity.setUpdatedBy(entity.getUpdatedBy());
+                shallowEntity.setStatus(entity.getStatus());
+                shallowEntity.setVersion(entity.getVersion());
+
+                auditString = auditPrefix + AtlasType.toJson(shallowEntity);
+            }
 
             entity.setAttributes(attrValues);
+            entity.setRelationshipAttributes(relAttrValues);
         }
 
         restoreEntityAttributes(entity, prunedAttributes);

Reply via email to