Skip to content

Commit

Permalink
logger verbosity changes (#75)
Browse files Browse the repository at this point in the history
* schema content is not logged upon successful fast(de)serializer compilation by default
* success messages are logged after actual (de)serializer generation in FastSerdeCache
  • Loading branch information
flowenol authored Jul 31, 2020
1 parent 86f47dd commit 80ecbc2
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,9 @@ protected Class compileClass(final String className, Set<String> knownUsedFullyQ
codeModel.build(destination);

String filePath = destination.getAbsolutePath() + generatedSourcesPath + className + ".java";
LOGGER.info("Generated source file: " + filePath);

JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
String compileClassPathForCurrentFile = Utils.inferCompileDependencies(compileClassPath, filePath, knownUsedFullyQualifiedClassNameSet);
LOGGER.info("For source file: " + filePath + ", and the inferred compile class path: " + compileClassPathForCurrentFile);
int compileResult;
try {
/*
Expand All @@ -127,7 +125,9 @@ protected Class compileClass(final String className, Set<String> knownUsedFullyQ
* Keeping this config also does not bring any downgrade.
*
*/
LOGGER.info("Starting compilation for the generated source file: {} with the inferred compile class path: {}", filePath, compileClassPathForCurrentFile);
compileResult = compiler.run(null, null, null, "-cp", compileClassPathForCurrentFile, filePath, "-XDuseUnsharedTable");
LOGGER.info("Successfully compiled class {} defined at source file: {}", className, filePath);
} catch (Exception e) {
throw new FastSerdeGeneratorException("Unable to compile:" + className + " from source file: " + filePath, e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.linkedin.avro.fastserde;

import static com.linkedin.avro.fastserde.Utils.getSchemaFingerprint;
import static com.linkedin.avroutil1.compatibility.AvroCompatibilityHelper.getSchemaFullName;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.ParameterizedType;
Expand All @@ -15,6 +18,7 @@
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;

import org.apache.avro.Schema;
import org.apache.avro.generic.ColdGenericDatumReader;
import org.apache.avro.generic.ColdSpecificDatumReader;
Expand Down Expand Up @@ -292,8 +296,8 @@ public FastSerializer<?> getFastGenericSerializer(Schema schema) {
}

private String getSchemaKey(Schema writerSchema, Schema readerSchema) {
return String.valueOf(Math.abs(Utils.getSchemaFingerprint(writerSchema))) + Math.abs(
Utils.getSchemaFingerprint(readerSchema));
return String.valueOf(Math.abs(getSchemaFingerprint(writerSchema))) + Math.abs(
getSchemaFingerprint(readerSchema));
}

/**
Expand All @@ -308,9 +312,20 @@ public FastDeserializer<?> buildFastSpecificDeserializer(Schema writerSchema, Sc
FastSpecificDeserializerGenerator<?> generator =
new FastSpecificDeserializerGenerator<>(writerSchema, readerSchema, classesDir, classLoader,
compileClassPath.orElseGet(() -> null));
LOGGER.info("Generated class dir: {}, and generation of specific FastDeserializer is done for writer schema: "
+ "[\n{}\n] and reader schema: [\n{}\n]", classesDir, writerSchema.toString(true), readerSchema.toString(true));
return generator.generateDeserializer();
FastDeserializer<?> fastDeserializer = generator.generateDeserializer();

if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Generated classes dir: {} and generation of specific FastDeserializer is done for writer schema of type: {} with fingerprint: {}"
+ " and content: [\n{}\n] and reader schema of type: {} with fingerprint: {} and content: [\n{}\n]", classesDir, getSchemaFullName(writerSchema),
writerSchema.toString(true), getSchemaFingerprint(writerSchema), getSchemaFullName(readerSchema), getSchemaFingerprint(readerSchema),
readerSchema.toString(true));
} else {
LOGGER.info("Generated classes dir: {} and generation of specific FastDeserializer is done for writer schema of type: {} with fingerprint: {}"
+ " and reader schema of type: {} with fingerprint: {}", classesDir, getSchemaFullName(writerSchema), getSchemaFingerprint(writerSchema),
getSchemaFullName(readerSchema), getSchemaFingerprint(readerSchema));
}

return fastDeserializer;
}

/**
Expand Down Expand Up @@ -352,9 +367,21 @@ public FastDeserializer<?> buildFastGenericDeserializer(Schema writerSchema, Sch
FastGenericDeserializerGenerator<?> generator =
new FastGenericDeserializerGenerator<>(writerSchema, readerSchema, classesDir, classLoader,
compileClassPath.orElseGet(() -> null));
LOGGER.info("Generated classes dir: {} and generation of generic FastDeserializer is done for writer schema: "
+ "[\n{}\n] and reader schema:[\n{}\n]", classesDir, writerSchema.toString(true), readerSchema.toString(true));
return generator.generateDeserializer();

FastDeserializer<?> fastDeserializer = generator.generateDeserializer();

if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Generated classes dir: {} and generation of generic FastDeserializer is done for writer schema of type: {} with fingerprint: {}"
+ " and content: [\n{}\n] and reader schema of type: {} with fingerprint: {} and content: [\n{}\n]", classesDir, getSchemaFullName(writerSchema),
writerSchema.toString(true), getSchemaFingerprint(writerSchema), getSchemaFullName(readerSchema), getSchemaFingerprint(readerSchema),
readerSchema.toString(true));
} else {
LOGGER.info("Generated classes dir: {} and generation of generic FastDeserializer is done for writer schema of type: {} with fingerprint: {}"
+ " and reader schema of type: {} with fingerprint: {}", classesDir, getSchemaFullName(writerSchema), getSchemaFingerprint(writerSchema),
getSchemaFullName(readerSchema), getSchemaFingerprint(readerSchema));
}

return fastDeserializer;
}

/**
Expand Down Expand Up @@ -393,8 +420,16 @@ public FastSerializer<?> buildFastSpecificSerializer(Schema schema) {
}
FastSpecificSerializerGenerator<?> generator =
new FastSpecificSerializerGenerator<>(schema, classesDir, classLoader, compileClassPath.orElseGet(() -> null));
LOGGER.info("Generated classes dir: {} and generation of specific FastSerializer is done for schema: [\n{}\n]",
classesDir, schema.toString(true));

if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Generated classes dir: {} and generation of specific FastSerializer is done for schema of type: {}" +
" and fingerprint: {} and content: [\n{}\n]", classesDir, getSchemaFullName(schema), getSchemaFingerprint(schema),
schema.toString(true));
} else {
LOGGER.info("Generated classes dir: {} and generation of specific FastSerializer is done for schema of type: {}" +
" and fingerprint: {}", classesDir, getSchemaFullName(schema), getSchemaFingerprint(schema));
}

return generator.generateSerializer();
}

Expand Down Expand Up @@ -429,8 +464,16 @@ public FastSerializer<?> buildFastGenericSerializer(Schema schema) {
}
FastGenericSerializerGenerator<?> generator =
new FastGenericSerializerGenerator<>(schema, classesDir, classLoader, compileClassPath.orElseGet(() -> null));
LOGGER.info("Generated classes dir: {} and generation of generic FastSerializer is done for schema: [\n{}\n]",
classesDir, schema.toString(true));

if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Generated classes dir: {} and generation of generic FastSerializer is done for schema of type: {}" +
" and fingerprint: {} and content: [\n{}\n]", classesDir, getSchemaFullName(schema), getSchemaFingerprint(schema),
schema.toString(true));
} else {
LOGGER.info("Generated classes dir: {} and generation of generic FastSerializer is done for schema of type: {}" +
" and fingerprint: {}", classesDir, getSchemaFullName(schema), getSchemaFingerprint(schema));
}

return generator.generateSerializer();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@

package com.linkedin.avroutil1.compatibility;

import com.linkedin.avroutil1.compatibility.avro14.Avro14Adapter;
import com.linkedin.avroutil1.compatibility.avro15.Avro15Adapter;
import com.linkedin.avroutil1.compatibility.avro16.Avro16Adapter;
import com.linkedin.avroutil1.compatibility.avro17.Avro17Adapter;
import com.linkedin.avroutil1.compatibility.avro18.Avro18Adapter;
import com.linkedin.avroutil1.compatibility.avro19.Avro19Adapter;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -20,6 +14,7 @@
import java.io.OutputStream;
import java.lang.reflect.Modifier;
import java.util.Collection;

import org.apache.avro.Schema;
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.IndexedRecord;
Expand All @@ -29,6 +24,13 @@
import org.apache.avro.io.JsonEncoder;
import org.apache.avro.specific.SpecificRecord;

import com.linkedin.avroutil1.compatibility.avro14.Avro14Adapter;
import com.linkedin.avroutil1.compatibility.avro15.Avro15Adapter;
import com.linkedin.avroutil1.compatibility.avro16.Avro16Adapter;
import com.linkedin.avroutil1.compatibility.avro17.Avro17Adapter;
import com.linkedin.avroutil1.compatibility.avro18.Avro18Adapter;
import com.linkedin.avroutil1.compatibility.avro19.Avro19Adapter;


/**
* a Utility class for performing various avro-related operations under a wide range of avro versions at runtime.
Expand Down Expand Up @@ -472,4 +474,20 @@ private static AvroVersion detectAvroVersion() {

return AvroVersion.AVRO_1_9;
}

/**
* Get the full schema name for records or type name for primitives. This adds compatibility
* layer for {@link Schema#getFullName} implementation in avro 1.4, which defaults to throwing exception.
*
* @param schema the schema whose full name should be retrieved
* @return full schema name or primitive type name
*/
public static String getSchemaFullName(Schema schema) {
try {
return schema.getFullName();
} catch (RuntimeException e) {
return schema.getType().name();
}
}

}

0 comments on commit 80ecbc2

Please sign in to comment.